]> git.tdb.fi Git - libs/core.git/blob - source/core/error.h
Make this thing actually compile
[libs/core.git] / source / core / error.h
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 #ifndef MSP_CORE_ERROR_H_
8 #define MSP_CORE_ERROR_H_
9
10 #include <exception>
11 #include <string>
12 #include "../debug/backtrace.h"
13
14 namespace Msp {
15
16 /**
17 Base class for all Msp exceptions.
18 */
19 class Exception: public std::exception
20 {
21 public:
22         Exception(const std::string &);
23         ~Exception() throw() { }
24
25         const char *what() const throw() { return w.c_str(); }
26         const Debug::Backtrace &get_backtrace() const throw() { return bt; }
27 private:
28         std::string w;
29         Debug::Backtrace bt;
30
31 };
32
33 /**
34 Thrown when a function parameter has an invalid value.
35 */
36 class InvalidParameterValue: public Exception
37 {
38 public:
39         InvalidParameterValue(const std::string &w_): Exception(w_) { }
40 };
41
42 /**
43 Thrown when the current object state doesn't allow the requested action.
44 */
45 class InvalidState: public Exception
46 {
47 public:
48         InvalidState(const std::string &w_): Exception(w_) { }
49 };
50
51 /**
52 Thrown when the application is invoked with wrong parameters.
53 */
54 class UsageError: public Exception
55 {
56 public:
57         UsageError(const std::string &r, bool b=true): Exception(r), brief(b) { }
58         bool get_brief() const { return brief; }
59 private:
60         bool brief;
61 };
62
63 /**
64 Thrown when a system call fails.
65 */
66 class SystemError: public Exception
67 {
68 public:
69         SystemError(const std::string &, int);
70         int get_error_code() const { return err; }
71 private:
72         int err;
73
74         static std::string build_what(const std::string &, int);
75 };
76
77 } // namespace Msp
78
79 #endif