+#include <typeinfo>
#include <signal.h>
+#include <msp/debug/demangle.h>
+#include <msp/debug/errorreporter.h>
#include <msp/io/print.h>
#include "application.h"
#include "getopt.h"
}
catch(const exception &e)
{
- delete app_;
+ bool handled = false;
+ if(const Debug::ErrorReporter *er = Debug::ErrorReporter::get_current())
+ handled = er->report_uncaught_exception(e);
- display_exception(e);
+ if(!handled)
+ {
+ IO::print(IO::cerr, "An uncaught exception occurred.\n");
+ IO::print(IO::cerr, " type: %s\n", Debug::demangle(typeid(e).name()));
+ IO::print(IO::cerr, " what(): %s\n", e.what());
+ }
+
+ delete app_;
return 124;
}
/** Static wrapper function to call a member function of the Application
instance. */
static void sighandler_(int);
-
- static void display_exception(const std::exception &);
};
+++ /dev/null
-#include <typeinfo>
-#include <msp/debug/demangle.h>
-#include <msp/io/print.h>
-#include "application.h"
-
-using namespace std;
-
-namespace Msp {
-
-void Application::display_exception(const exception &e)
-{
- IO::print(IO::cerr, "An uncaught exception occurred.\n");
- IO::print(IO::cerr, " type: %s\n", Debug::demangle(typeid(e).name()));
- IO::print(IO::cerr, " what(): %s\n", e.what());
-}
-
-} // namespace Msp
+++ /dev/null
-#include <windows.h>
-#include <typeinfo>
-#include <msp/debug/demangle.h>
-#include "application.h"
-
-using namespace std;
-
-namespace Msp {
-
-void Application::display_exception(const exception &e)
-{
- string msg = Debug::demangle(typeid(e).name())+":\n"+e.what();
- MessageBoxA(0, msg.c_str(), "Uncaught exception", MB_OK|MB_ICONERROR);
-}
-
-} // namespace Msp
--- /dev/null
+#include "errorreporter.h"
+
+namespace Msp {
+namespace Debug {
+
+ErrorReporter *ErrorReporter::current = 0;
+
+ErrorReporter::ErrorReporter():
+ prev(current)
+{
+ current = this;
+}
+
+ErrorReporter::~ErrorReporter()
+{
+ current = prev;
+}
+
+} // namespace Debug
+} // namespace Msp
--- /dev/null
+#ifndef MSP_DEBUG_ERRORREPORTER_H_
+#define MSP_DEBUG_ERRORREPORTER_H_
+
+#include <stdexcept>
+
+namespace Msp {
+namespace Debug {
+
+class ErrorReporter
+{
+private:
+ ErrorReporter *prev;
+
+ static ErrorReporter *current;
+
+protected:
+ ErrorReporter();
+public:
+ virtual ~ErrorReporter();
+
+ static const ErrorReporter *get_current() { return current; }
+
+ virtual bool report_uncaught_exception(const std::exception &) const = 0;
+};
+
+} // namespace Debug
+} // namespace Msp
+
+#endif