3 This file is part of libmspcore
4 Copyright © 2006-2008 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #ifndef MSP_CORE_ERROR_H_
9 #define MSP_CORE_ERROR_H_
13 #include "../debug/backtrace.h"
18 Base class for all Msp exceptions.
20 class Exception: public std::exception
28 Exception(const std::string &);
29 ~Exception() throw() { }
31 const char *what() const throw() { return wot.c_str(); }
32 Exception &at(const std::string &) throw();
33 const char *where() const throw() { return wer.c_str(); }
34 const Debug::Backtrace &get_backtrace() const throw() { return bt; }
38 Thrown when a function parameter has an invalid value.
40 class InvalidParameterValue: public Exception
43 InvalidParameterValue(const std::string &w_): Exception(w_) { }
47 Thrown when a lookup from a map fails.
49 class KeyError: public Exception
55 KeyError(const std::string &w_): Exception(w_) { }
56 KeyError(const std::string &w_, const std::string &k);
57 ~KeyError() throw() { }
59 const std::string &get_key() const { return key; }
63 Thrown when the current object state doesn't allow the requested action.
65 class InvalidState: public Exception
68 InvalidState(const std::string &w_): Exception(w_) { }
72 Thrown when the application is invoked with wrong parameters.
74 class UsageError: public Exception
80 UsageError(const std::string &r, bool b=true): Exception(r), brief(b) { }
81 bool get_brief() const { return brief; }
85 Thrown when a system call fails.
87 class SystemError: public Exception
93 SystemError(const std::string &, int);
94 int get_error_code() const { return err; }
97 static std::string build_what(const std::string &, int);
101 void throw_at(E e, const std::string &a)
102 { e.at(a); throw e; }