]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/error.cpp
Assimilate exceptions and RefPtr from mspmisc
[libs/core.git] / source / core / error.cpp
diff --git a/source/core/error.cpp b/source/core/error.cpp
new file mode 100644 (file)
index 0000000..727fa21
--- /dev/null
@@ -0,0 +1,40 @@
+/* $Id$
+
+This file is part of libmspcore
+Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+#include <sstream>
+#include "backtrace.h"
+#include "error.h"
+
+using namespace std;
+
+namespace Msp {
+
+Exception::Exception(const string &w_):
+       w(w_)
+{
+#ifdef WITH_EXCEPTION_BACKTRACE
+       bt=Backtrace::create();
+#endif
+}
+
+SystemError::SystemError(const string &w_, int e):
+       Exception(build_what(w_, e)),
+       err(e)
+{ }
+
+string SystemError::build_what(const string &w, int e)
+{
+       ostringstream buf;
+       buf<<w<<": ";
+#ifdef WIN32
+       buf<<e;
+#else
+       buf<<strerror(e);
+#endif
+       return buf.str();
+}
+
+} // namespace Msp