Commit 5999b560e70d0558bd23e2ee436f0905fa182e93
1 parent
402b67ad
add try-catch around application
Showing
2 changed files
with
26 additions
and
5 deletions
src/ctselect/ctselect.cpp
| @@ -32,11 +32,23 @@ | @@ -32,11 +32,23 @@ | ||
| 32 | ***************************************************************************/ | 32 | ***************************************************************************/ |
| 33 | int main (int argc, char *argv[]) | 33 | int main (int argc, char *argv[]) |
| 34 | { | 34 | { |
| 35 | - // Create instance of application | ||
| 36 | - ctselect application(argc, argv); | 35 | + // Initialise return code |
| 36 | + int rc = 0; | ||
| 37 | 37 | ||
| 38 | - // Run application | ||
| 39 | - int rc = application.run(); | 38 | + // Put all code in try-catch brackets to catch all errors |
| 39 | + try { | ||
| 40 | + | ||
| 41 | + // Create instance of application | ||
| 42 | + ctselect application(argc, argv); | ||
| 43 | + | ||
| 44 | + // Run application | ||
| 45 | + rc = application.run(); | ||
| 46 | + | ||
| 47 | + } | ||
| 48 | + catch (std::exception &e) { | ||
| 49 | + std::cout << e.what() << std::endl; | ||
| 50 | + rc = -1; | ||
| 51 | + } | ||
| 40 | 52 | ||
| 41 | // Return | 53 | // Return |
| 42 | return rc; | 54 | return rc; |
| @@ -51,6 +63,15 @@ int ctselect::run(void) | @@ -51,6 +63,15 @@ int ctselect::run(void) | ||
| 51 | // Test dump | 63 | // Test dump |
| 52 | std::cout << *this << std::endl; | 64 | std::cout << *this << std::endl; |
| 53 | 65 | ||
| 66 | + // DUMMY FOR TESTING | ||
| 67 | + std::string value; | ||
| 68 | + value = par("string")->value(); | ||
| 69 | + std::cout << value << std::endl; | ||
| 70 | + value = par("chatter")->value(); | ||
| 71 | + std::cout << value << std::endl; | ||
| 72 | + value = par("clobber")->value(); | ||
| 73 | + std::cout << value << std::endl; | ||
| 74 | + | ||
| 54 | // Return | 75 | // Return |
| 55 | return 0; | 76 | return 0; |
| 56 | } | 77 | } |
src/ctselect/ctselect.hpp
| @@ -35,7 +35,7 @@ | @@ -35,7 +35,7 @@ | ||
| 35 | class ctselect : public GApplication { | 35 | class ctselect : public GApplication { |
| 36 | public: | 36 | public: |
| 37 | // Constructors and destructors | 37 | // Constructors and destructors |
| 38 | - ctselect(int argc, char *argv[]) : | 38 | + ctselect(int argc, char *argv[]) : |
| 39 | GApplication(APP_NAME, APP_VERSION, argc, argv) { return; } | 39 | GApplication(APP_NAME, APP_VERSION, argc, argv) { return; } |
| 40 | 40 | ||
| 41 | // Methods | 41 | // Methods |