X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fexcept.h;fp=source%2Fcore%2Fexcept.h;h=d030c41c12937e1a3846ce819c445cd2b953e308;hb=c13c5d2e330e4cee177c1fd8e0b6153c7e2503e4;hp=0000000000000000000000000000000000000000;hpb=55a79fbe96a87183fa4e11049eb161943636b1dd;p=libs%2Fcore.git diff --git a/source/core/except.h b/source/core/except.h new file mode 100644 index 0000000..d030c41 --- /dev/null +++ b/source/core/except.h @@ -0,0 +1,88 @@ +/* $Id$ + +This file is part of libmspcore +Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ +#ifndef MSP_CORE_ERROR_H_ +#define MSP_CORE_ERROR_H_ + +#include +#include +#include "../debug/backtrace.h" + +namespace Msp { + +/** +Base class for all Msp exceptions. +*/ +class Exception: public std::exception +{ +public: + Exception(const std::string &); + ~Exception() throw() { } + + const char *what() const throw() { return w.c_str(); } + const Debug::Backtrace &get_backtrace() const throw() { return bt; } +private: + std::string w; + Debug::Backtrace bt; + +}; + +/** +Thrown when a function parameter has an invalid value. +*/ +class InvalidParameterValue: public Exception +{ +public: + InvalidParameterValue(const std::string &w_): Exception(w_) { } +}; + +/** +Thrown when a lookup from a map fails. +*/ +class KeyError: public Exception +{ +public: + KeyError(const std::string &w_): Exception(w_) { } +}; + +/** +Thrown when the current object state doesn't allow the requested action. +*/ +class InvalidState: public Exception +{ +public: + InvalidState(const std::string &w_): Exception(w_) { } +}; + +/** +Thrown when the application is invoked with wrong parameters. +*/ +class UsageError: public Exception +{ +public: + UsageError(const std::string &r, bool b=true): Exception(r), brief(b) { } + bool get_brief() const { return brief; } +private: + bool brief; +}; + +/** +Thrown when a system call fails. +*/ +class SystemError: public Exception +{ +public: + SystemError(const std::string &, int); + int get_error_code() const { return err; } +private: + int err; + + static std::string build_what(const std::string &, int); +}; + +} // namespace Msp + +#endif