It allows a user to replace code such as:
char const PROGRAM_NAME[] = "myprogram"; int main(int argc, char** argv) { try { . . . // program logic return EXIT_SUCCESS; } catch(std::bad_alloc&) { pantheios::logputs(pantheios::alert, "out of memory"); fprintf(stderr, "%s: out of memory\n", PROGRAM_NAME); } catch(std::exception& x) { pantheios::log_CRITICAL(x); fprintf(stderr, "%s: %s\n", PROGRAM_NAME, x.what()); } catch(...) { pantheios::logputs(pantheios::emergency, "unexpected unknown failure"); fprintf(stderr, "%s: unexpected unknown failure\n", PROGRAM_NAME); } return EXIT_FAILURE; }
with:
char const PROGRAM_NAME[] = "myprogram"; int program(int argc, char** argv) { . . . // program logic return EXIT_SUCCESS; } int main(int argc, char** argv) { return pantheios::extras::main::invoke(argc, argv, program, PROGRAM_NAME); }
As discussed in the sixth instalment of Quality Matters, Exceptions for Practically-Unrecoverable Conditions, without an exhaustive top-level try-catch statement, program robustness cannot be averred. Pantheios.Extras.Main let's you achieve that in a single statement.
No comments:
Post a Comment