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