Skip to content

Commit f63dc86

Browse files
Dmitry-Medanmar
authored andcommitted
Must catch and translate exceptions on top level
1 parent 47a3548 commit f63dc86

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

cli/main.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,17 @@ int main(int argc, char* argv[])
119119
GetModuleFileNameA(NULL, exename, sizeof(exename)/sizeof(exename[0])-1);
120120
argv[0] = exename;
121121
#endif
122-
return exec.check(argc, argv);
122+
123+
try {
124+
return exec.check(argc, argv);
125+
} catch (const InternalError& e) {
126+
printf("%s\n", e.errorMessage.c_str());
127+
} catch (const std::exception& error) {
128+
printf("%s\n", error.what());
129+
} catch (...) {
130+
printf("Unknown exception\n");
131+
}
132+
return EXIT_FAILURE;
123133
}
124134

125135

test/testrunner.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,17 @@
2222

2323
int main(int argc, char *argv[])
2424
{
25-
options args(argc, const_cast<const char**>(argv));
25+
try {
26+
options args(argc, const_cast<const char**>(argv));
2627

27-
std::size_t failedTestsCount = TestFixture::runTests(args);
28-
29-
return (failedTestsCount == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
28+
std::size_t failedTestsCount = TestFixture::runTests(args);
29+
return (failedTestsCount == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
30+
} catch (const InternalError& e) {
31+
printf("%s\n", e.errorMessage.c_str());
32+
} catch (const std::exception& error) {
33+
printf("%s\n", error.what());
34+
} catch (...) {
35+
printf("Unknown exception\n");
36+
}
37+
return EXIT_FAILURE;
3038
}

0 commit comments

Comments
 (0)