Commit 5f32157f7870c4697682f7407613b25b37e566ec
1 parent
cea4f2eb
add application error catching
Showing
3 changed files
with
74 additions
and
8 deletions
src/ctbin/main.cpp
| ... | ... | @@ -35,11 +35,33 @@ |
| 35 | 35 | ***************************************************************************/ |
| 36 | 36 | int main (int argc, char *argv[]) |
| 37 | 37 | { |
| 38 | + // Initialise return code | |
| 39 | + int rc = 1; | |
| 40 | + | |
| 38 | 41 | // Create instance of application |
| 39 | 42 | ctbin application(argc, argv); |
| 40 | - | |
| 43 | + | |
| 41 | 44 | // Run application |
| 42 | - int rc = application.run(); | |
| 45 | + try { | |
| 46 | + application.run(); | |
| 47 | + rc = 0; | |
| 48 | + } | |
| 49 | + catch (std::exception &e) { | |
| 50 | + | |
| 51 | + // Extract error message | |
| 52 | + std::string message = e.what(); | |
| 53 | + std::string signal = "*** ERROR encounterted in the execution of" | |
| 54 | + " ctbin. Run aborted ..."; | |
| 55 | + | |
| 56 | + // Write error in logger | |
| 57 | + application.log << signal << std::endl; | |
| 58 | + application.log << message << std::endl; | |
| 59 | + | |
| 60 | + // Write error on standard output | |
| 61 | + std::cout << signal << std::endl; | |
| 62 | + std::cout << message << std::endl; | |
| 63 | + | |
| 64 | + } // endcatch: catched any application error | |
| 43 | 65 | |
| 44 | 66 | // Return |
| 45 | 67 | return rc; | ... | ... |
src/ctlike/main.cpp
| ... | ... | @@ -32,12 +32,34 @@ |
| 32 | 32 | ***************************************************************************/ |
| 33 | 33 | int main (int argc, char *argv[]) |
| 34 | 34 | { |
| 35 | + // Initialise return code | |
| 36 | + int rc = 1; | |
| 37 | + | |
| 35 | 38 | // Create instance of application |
| 36 | 39 | ctlike application(argc, argv); |
| 37 | - | |
| 40 | + | |
| 38 | 41 | // Run application |
| 39 | - application.run(); | |
| 42 | + try { | |
| 43 | + application.run(); | |
| 44 | + rc = 0; | |
| 45 | + } | |
| 46 | + catch (std::exception &e) { | |
| 47 | + | |
| 48 | + // Extract error message | |
| 49 | + std::string message = e.what(); | |
| 50 | + std::string signal = "*** ERROR encounterted in the execution of" | |
| 51 | + " ctlike. Run aborted ..."; | |
| 52 | + | |
| 53 | + // Write error in logger | |
| 54 | + application.log << signal << std::endl; | |
| 55 | + application.log << message << std::endl; | |
| 56 | + | |
| 57 | + // Write error on standard output | |
| 58 | + std::cout << signal << std::endl; | |
| 59 | + std::cout << message << std::endl; | |
| 60 | + | |
| 61 | + } // endcatch: catched any application error | |
| 40 | 62 | |
| 41 | 63 | // Return |
| 42 | - return 0; | |
| 64 | + return rc; | |
| 43 | 65 | } | ... | ... |
src/ctselect/main.cpp
| ... | ... | @@ -32,12 +32,34 @@ |
| 32 | 32 | ***************************************************************************/ |
| 33 | 33 | int main (int argc, char *argv[]) |
| 34 | 34 | { |
| 35 | + // Initialise return code | |
| 36 | + int rc = 1; | |
| 37 | + | |
| 35 | 38 | // Create instance of application |
| 36 | 39 | ctselect application(argc, argv); |
| 37 | - | |
| 40 | + | |
| 38 | 41 | // Run application |
| 39 | - application.run(); | |
| 42 | + try { | |
| 43 | + application.run(); | |
| 44 | + rc = 0; | |
| 45 | + } | |
| 46 | + catch (std::exception &e) { | |
| 47 | + | |
| 48 | + // Extract error message | |
| 49 | + std::string message = e.what(); | |
| 50 | + std::string signal = "*** ERROR encounterted in the execution of" | |
| 51 | + " ctselect. Run aborted ..."; | |
| 52 | + | |
| 53 | + // Write error in logger | |
| 54 | + application.log << signal << std::endl; | |
| 55 | + application.log << message << std::endl; | |
| 56 | + | |
| 57 | + // Write error on standard output | |
| 58 | + std::cout << signal << std::endl; | |
| 59 | + std::cout << message << std::endl; | |
| 60 | + | |
| 61 | + } // endcatch: catched any application error | |
| 40 | 62 | |
| 41 | 63 | // Return |
| 42 | - return 0; | |
| 64 | + return rc; | |
| 43 | 65 | } | ... | ... |