1 #ifndef MSP_CORE_ERROR_H_
2 #define MSP_CORE_ERROR_H_
6 #include "../debug/backtrace.h"
11 Base class for all Msp exceptions.
13 class Exception: public std::exception
21 Exception(const std::string &);
22 ~Exception() throw() { }
24 const char *what() const throw() { return wot.c_str(); }
25 Exception &at(const std::string &) throw();
26 const char *where() const throw() { return wer.c_str(); }
27 const Debug::Backtrace &get_backtrace() const throw() { return bt; }
31 Thrown when a function parameter has an invalid value.
33 class InvalidParameterValue: public Exception
36 InvalidParameterValue(const std::string &w_): Exception(w_) { }
40 Thrown when a lookup from a map fails.
42 class KeyError: public Exception
48 KeyError(const std::string &w_): Exception(w_) { }
49 KeyError(const std::string &w_, const std::string &k);
50 ~KeyError() throw() { }
52 const std::string &get_key() const { return key; }
56 Thrown when the current object state doesn't allow the requested action.
58 class InvalidState: public Exception
61 InvalidState(const std::string &w_): Exception(w_) { }
65 Thrown when the application is invoked with wrong parameters.
67 class UsageError: public Exception
73 UsageError(const std::string &r, bool b = true): Exception(r), brief(b) { }
74 bool get_brief() const { return brief; }
78 Thrown when a system call fails.
80 class SystemError: public Exception
86 SystemError(const std::string &, int);
87 int get_error_code() const { return err; }
90 static std::string build_what(const std::string &, int);
94 Thrown when "impossible" things happen.
96 class LogicError: public Exception
99 LogicError(const std::string &w_): Exception(w_) { }
103 void throw_at(E e, const std::string &a)
104 { e.at(a); throw e; }