Skip to content

Commit

Permalink
log uncaught C++ exceptions in main
Browse files Browse the repository at this point in the history
Summary:
Uncaught C++ exceptions on Windows aren't logged in a very helpful
way. Print a more useful message to the log.

Reviewed By: wez

Differential Revision: D21671280

fbshipit-source-id: f450ed7bcd2ccabf999ea0eae5ed18442f80a3a3
  • Loading branch information
chadaustin authored and facebook-github-bot committed Jul 18, 2020
1 parent a26c0f2 commit c400ffd
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ static void spawn_watchman(void) {
#endif
}

int main(int argc, char** argv) {
static int inner_main(int argc, char** argv) {
// Since we don't fully integrate with folly, but may pull
// in dependencies that do, we need to perform a little bit
// of bootstrapping. We don't want to run the full folly
Expand Down Expand Up @@ -1349,5 +1349,20 @@ int main(int argc, char** argv) {
return 1;
}

int main(int argc, char** argv) {
try {
return inner_main(argc, argv);
} catch (const std::exception& e) {
log(ERR,
"Uncaught C++ exception: ",
folly::exceptionStr(e).toStdString(),
"\n");
return 1;
} catch (...) {
log(ERR, "Uncaught C++ exception: ...\n");
return 1;
}
}

/* vim:ts=2:sw=2:et:
*/

0 comments on commit c400ffd

Please sign in to comment.