X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fexcept.h;h=a58b3ca9c0c9480b14560a36a160aa247be42542;hb=6728e37df7f74130689d3829a1466422451735e3;hp=a18e028730aedddac1d044de1b98b4fa36edea21;hpb=9de64375e03b24ea46d36cec222150754e3818cb;p=libs%2Fcore.git diff --git a/source/core/except.h b/source/core/except.h index a18e028..a58b3ca 100644 --- a/source/core/except.h +++ b/source/core/except.h @@ -1,9 +1,10 @@ /* $Id$ This file is part of libmspcore -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2008 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ + #ifndef MSP_CORE_ERROR_H_ #define MSP_CORE_ERROR_H_ @@ -18,16 +19,19 @@ Base class for all Msp exceptions. */ class Exception: public std::exception { +private: + std::string wot; + std::string wer; + Debug::Backtrace bt; + public: Exception(const std::string &); ~Exception() throw() { } - const char *what() const throw() { return w.c_str(); } + const char *what() const throw() { return wot.c_str(); } + Exception &at(const std::string &) throw(); + const char *where() const throw() { return wer.c_str(); } const Debug::Backtrace &get_backtrace() const throw() { return bt; } -private: - std::string w; - Debug::Backtrace bt; - }; /** @@ -44,12 +48,15 @@ Thrown when a lookup from a map fails. */ class KeyError: public Exception { +private: + std::string key; + public: KeyError(const std::string &w_): Exception(w_) { } - KeyError(const std::string &w_, const std::string &k) { } + KeyError(const std::string &w_, const std::string &k); + ~KeyError() throw() { } + const std::string &get_key() const { return key; } -private: - std::string key; }; /** @@ -66,11 +73,12 @@ 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; + +public: + UsageError(const std::string &r, bool b = true): Exception(r), brief(b) { } + bool get_brief() const { return brief; } }; /** @@ -78,15 +86,30 @@ Thrown when a system call fails. */ class SystemError: public Exception { +private: + int err; + public: SystemError(const std::string &, int); int get_error_code() const { return err; } -private: - int err; +private: static std::string build_what(const std::string &, int); }; +/** +Thrown when "impossible" things happen. +*/ +class LogicError: public Exception +{ +public: + LogicError(const std::string &w_): Exception(w_) { } +}; + +template +void throw_at(E e, const std::string &a) +{ e.at(a); throw e; } + } // namespace Msp #endif