]> git.tdb.fi Git - libs/core.git/blob - source/core/except.cpp
Remove an obsolete Makefile
[libs/core.git] / source / core / except.cpp
1 /* $Id$
2
3 This file is part of libmspcore
4 Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include <sstream>
9 #include <cstring>
10 #ifdef WIN32
11 #include <windows.h>
12 #endif
13 #include "except.h"
14
15 using namespace std;
16
17 namespace Msp {
18
19 Exception::Exception(const string &w_):
20         w(w_)
21 {
22 #ifdef WITH_EXCEPTION_BACKTRACE
23         bt=Debug::Backtrace::create();
24 #endif
25 }
26
27 SystemError::SystemError(const string &w_, int e):
28         Exception(build_what(w_, e)),
29         err(e)
30 { }
31
32 KeyError::KeyError(const string &w_, const string &k):
33         Exception(w_+" ("+k+")"),
34         key(k)
35 { }
36
37 string SystemError::build_what(const string &w, int e)
38 {
39         ostringstream buf;
40         buf<<w<<": ";
41 #ifdef WIN32
42         char msg[1024];
43         if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, e, 0, msg, sizeof(msg), 0))
44                 buf<<msg;
45         else
46                 buf<<e;
47 #else
48         buf<<strerror(e);
49 #endif
50         return buf.str();
51 }
52
53 } // namespace Msp