]> git.tdb.fi Git - libs/core.git/blob - source/core/except.cpp
Drop copyright and license notices from source files
[libs/core.git] / source / core / except.cpp
1 #include <sstream>
2 #include <cstring>
3 #ifdef WIN32
4 #include <windows.h>
5 #endif
6 #include "except.h"
7
8 using namespace std;
9
10 namespace Msp {
11
12 Exception::Exception(const string &w):
13         wot(w)
14 {
15 #ifdef WITH_EXCEPTION_BACKTRACE
16         bt = Debug::Backtrace::create();
17 #endif
18 }
19
20 Exception &Exception::at(const std::string &w) throw()
21 {
22         wer = w;
23         wot = wer+": "+wot;
24         return *this;
25 }
26
27
28 SystemError::SystemError(const string &w_, int e):
29         Exception(build_what(w_, e)),
30         err(e)
31 { }
32
33 string SystemError::build_what(const string &w, int e)
34 {
35         ostringstream buf;
36         buf<<w<<": ";
37 #ifdef WIN32
38         char msg[1024];
39         if(FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, e, 0, msg, sizeof(msg), 0))
40                 buf<<msg;
41         else
42                 buf<<e;
43 #else
44         buf<<strerror(e);
45 #endif
46         return buf.str();
47 }
48
49
50 KeyError::KeyError(const string &w_, const string &k):
51         Exception(w_+" ("+k+")"),
52         key(k)
53 { }
54
55 } // namespace Msp