]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/application.cpp
Reorder components to get headers install correctly
[libs/core.git] / source / core / application.cpp
index 7e92dbdf3d552574fbb279b17abc7bf56edfbec2..47c176bd8a882a6869df467e7330f2274bfcc5e4 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"
 
@@ -38,17 +40,28 @@ int Application::run(int argc, char **argv)
 
        try
        {
-               app_=reg_app_->create_app(argc, argv);
+               try
+               {
+                       app_=reg_app_->create_app(argc, argv);
+               }
+               catch(const UsageError &e)
+               {
+                       reg_app_->usage(e.what(), argv[0], e.get_brief());
+                       return 1;
+               }
+
+               int result=app_->main();
+               delete app_;
+               return result;
        }
-       catch(const UsageError &e)
+       catch(const exception &e)
        {
-               reg_app_->usage(e.what(), argv[0], e.get_brief());
-               return 1;
+               cerr<<"An uncaught exception occurred.\n";
+               cerr<<"  type:   "<<typeid(e).name()<<'\n';
+               cerr<<"  what(): "<<e.what()<<'\n';
+               delete app_;
+               throw;
        }
-
-       int result=app_->main();
-       delete app_;
-       return result;
 }
 
 /**
@@ -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)
                {