]> git.tdb.fi Git - libs/core.git/blob - source/core/except.cpp
7ac634d9a30c9ef9c8f8dec01633b5c950c96ef8
[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 #include "except.h"
11
12 using namespace std;
13
14 namespace Msp {
15
16 Exception::Exception(const string &w_):
17         w(w_)
18 {
19 #ifdef WITH_EXCEPTION_BACKTRACE
20         bt=Debug::Backtrace::create();
21 #endif
22 }
23
24 SystemError::SystemError(const string &w_, int e):
25         Exception(build_what(w_, e)),
26         err(e)
27 { }
28
29 KeyError::KeyError(const string &w_, const string &k):
30         Exception(w_+" ("+k+")"),
31         key(k)
32 { }
33
34 string SystemError::build_what(const string &w, int e)
35 {
36         ostringstream buf;
37         buf<<w<<": ";
38 #ifdef WIN32
39         buf<<e;
40 #else
41         buf<<strerror(e);
42 #endif
43         return buf.str();
44 }
45
46 } // namespace Msp