Skip to content

Commit 73171b0

Browse files
committed
Catch exceptions in main() only if NDEBUG is defined
1 parent 03b1afc commit 73171b0

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

cli/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ int main(int argc, char* argv[])
123123
argv[0] = exename;
124124
#endif
125125

126+
#ifdef NDEBUG
126127
try {
128+
#endif
127129
return exec.check(argc, argv);
130+
#ifdef NDEBUG
128131
} catch (const InternalError& e) {
129132
printf("%s\n", e.errorMessage.c_str());
130133
} catch (const std::exception& error) {
@@ -133,6 +136,7 @@ int main(int argc, char* argv[])
133136
printf("Unknown exception\n");
134137
}
135138
return EXIT_FAILURE;
139+
#endif
136140
}
137141

138142

test/testrunner.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323

2424
int main(int argc, char *argv[])
2525
{
26+
#ifdef NDEBUG
2627
try {
28+
#endif
2729
options args(argc, const_cast<const char**>(argv));
2830

2931
std::size_t failedTestsCount = TestFixture::runTests(args);
3032
return (failedTestsCount == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
33+
#ifdef NDEBUG
3134
} catch (const InternalError& e) {
3235
printf("%s\n", e.errorMessage.c_str());
3336
} catch (const std::exception& error) {
@@ -36,4 +39,5 @@ int main(int argc, char *argv[])
3639
printf("Unknown exception\n");
3740
}
3841
return EXIT_FAILURE;
42+
#endif
3943
}

0 commit comments

Comments
 (0)