X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Ferror.h;h=1f9662e274b1d9b087d9cb16e5c1cf30f8c6811b;hp=a8ad2939daa72bb5021719fa1da126a0b151efba;hb=521cf1db00f8ce2d9f9494dca503d6c17d89ac2f;hpb=80bbee2f401b4af71cb1b80508bdb0d2bb61fa40 diff --git a/source/core/error.h b/source/core/error.h index a8ad293..1f9662e 100644 --- a/source/core/error.h +++ b/source/core/error.h @@ -1,16 +1,57 @@ -/* +/* $Id$ + This file is part of libmspcore -Copyright © 2006 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#ifndef MSP_FRAMEWORK_ERRORS_H_ -#define MSP_FRAMEWORK_ERRORS_H_ +#ifndef MSP_CORE_ERROR_H_ +#define MSP_CORE_ERROR_H_ -#include +#include +#include +#include "backtrace.h" namespace Msp { -class UsageError: public Msp::Exception +/** +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 Backtrace &get_backtrace() const throw() { return bt; } +private: + std::string w; + 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 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) { } @@ -19,6 +60,20 @@ 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