]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/application.cpp
Trap and explain uncaught exceptions
[libs/core.git] / source / core / application.cpp
index 7e92dbdf3d552574fbb279b17abc7bf56edfbec2..0ef3443e8eac4fab7173b15df42c9cd1360b4e88 100644 (file)
@@ -1,4 +1,5 @@
-/*
+/* $Id$
+
 This file is part of libmspcore
 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
@@ -6,6 +7,7 @@ Distributed under the LGPL
 #include <signal.h>
 #include <iostream>
 #include "../time/units.h"
+#include "../time/utils.h"
 #include "application.h"
 #include "error.h"
 
@@ -46,9 +48,20 @@ int Application::run(int argc, char **argv)
                return 1;
        }
 
-       int result=app_->main();
-       delete app_;
-       return result;
+       try
+       {
+               int result=app_->main();
+               delete app_;
+               return result;
+       }
+       catch(const exception &e)
+       {
+               cerr<<"An uncaught exception occurred.\n";
+               cerr<<"  type:   "<<typeid(e).name()<<'\n';
+               cerr<<"  what(): "<<e.what()<<'\n';
+               delete app_;
+               throw;
+       }
 }
 
 /**
@@ -62,7 +75,7 @@ will blame the programmer for being lazy.
 void Application::usage(const char *reason, const char *, bool)
 {
        if(reason)
-               cerr<<reason<<'\n';
+               cerr<<"UsageError: "<<reason<<'\n';
        cerr<<"The programmer was lazy and didn't write a usage() function for this application.\n";
 }
 
@@ -92,7 +105,7 @@ int Application::main()
                else if(loop_mode_==TICK_SLEEP)
                {
                        tick();
-                       sleep(Time::msec);
+                       Time::sleep(Time::msec);
                }
                else if(loop_mode_==TICK_YIELD)
                {