X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FException.hh;h=c6e9ba35758b6534ec231d1458da376b28d4e576;hb=82ad2ed94c12c3e53097fef92978de8c28239fab;hp=7d5dbf1e557f85b83c7ef4ea44985952f784bd14;hpb=ac6a813d9d99f7add4e13aff7a4bcd314d5604a6;p=senf.git diff --git a/Utils/Exception.hh b/Utils/Exception.hh index 7d5dbf1..c6e9ba3 100644 --- a/Utils/Exception.hh +++ b/Utils/Exception.hh @@ -1,6 +1,6 @@ // $Id$ // -// Copyright (C) 2006 +// Copyright (C) 2006 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) // Kompetenzzentrum fuer Satelitenkommunikation (SatCom) // Stefan Bund @@ -20,45 +20,107 @@ // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/** \file + \brief Exception public header */ + #ifndef HH_Exception_ #define HH_Exception_ 1 // Custom includes #include #include +#include +#include //#include "Exception.mpp" ///////////////////////////////hh.p//////////////////////////////////////// namespace senf { + /** \brief Exception handling standard UNIX errors (errno) + + This exception is thrown to signal generic errno failures. + + \todo make where and err accessors and make the member variables private - struct SystemException : public std::exception + \idea Add a template class derived from SystemException which takes the error number as a + numeric argument. This allows catching specific errno conditions: ErrnoException etc. + + \idea Add a generic error thrower which takes the origin string and errno value as an + argument and will throw a corresponding template class instance. This would just be a big + switch statement containing all possible errno values, probably created using some macro + meta-programming. + */ + class SystemException : public std::exception { - explicit SystemException(int err_) : where(0), err(err_) { init(); } - SystemException(char const * where_, int err_) : where(where_), err(err_) { init(); } + public: + SystemException(); ///< SystemException without error location infor + /**< The error code is taken from the current value of the + global 'errno' variable */ + + explicit SystemException(int code); ///< SystemException without error location info + /**< \param[in] code error number (the errno value) */ + + explicit SystemException(char const * where); ///< SystemException with error location info + /**< The error code is taken from the current value of the + global 'errno' variable + \param[in] where description of error origin */ + + SystemException(char const * where, int code); ///< SystemException with error location info + /**< \param[in] where description of error origin + \param[in] code error number (the errno value) */ + + virtual char const * what() const throw(); ///< Return verbose error description + + char const * where() const; ///< Error origin + int code() const; ///< Error code (errno number) + char const * description() const; ///< Error description (strerror() value) - virtual char const * what() const throw(); + bool anyOf(int c0, int c1=0, int c2=0, int c3=0, int c4=0, int c5=0, + int c6=0, int c7=0, int c8=0, int c9=0); - char const * where; - int err; + virtual ~SystemException() throw(); - virtual ~SystemException() throw() {} private: void init(); - std::string buffer_; + + char const * const where_; + int const code_; + std::string buffer_; + }; + + template + class ErrnoException : public SystemException + { + public: + static int const fixed_code = Code; + + ErrnoException(); + explicit ErrnoException(char const * where); }; - + + void throwErrno(); + void throwErrno(char const * where); + void throwErrno(int code); + void throwErrno(char const * where, int code); + + enum NoThrow_t { nothrow }; + } ///////////////////////////////hh.e//////////////////////////////////////// -//#include "Exception.cci" +#include "Exception.cci" //#include "Exception.ct" -//#include "Exception.cti" +#include "Exception.cti" #endif // Local Variables: // mode: c++ +// fill-column: 100 // c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 // End: