From: Christian P. <cp...@us...> - 2005-07-01 13:53:02
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16708/include/pclasses Modified Files: Exception.h Log Message: - Removed std::string from Exception. The base exception should not throw in any case - Fixed CmdLineError and added extra exception info field Index: Exception.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Exception.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Exception.h 20 Jan 2005 22:16:13 -0000 1.5 +++ Exception.h 1 Jul 2005 13:52:51 -0000 1.6 @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2004 by Christian Prochnow * + * Copyright (C) 2004,2005 by Christian Prochnow, SecuLogiX GmbH * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * @@ -18,16 +18,17 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef _P_Exception_h_ -#define _P_Exception_h_ +#ifndef P_Exception_h +#define P_Exception_h -#include <string> #include <pclasses/Export.h> #include <pclasses/SourceInfo.h> +#include <string> namespace P { -/** +//! Exception base class +/*! This is the base Exception class for the P framework. Exception uses a non-traditional ctor, requiring a SourceInfo @@ -35,49 +36,66 @@ throw MyException( "dammit!", P_SOURCEINFO ); +Cause exception objects must not allocate memory when thrown, the +what argument to the Exception ctor must be a statically allocated +string. + Clients may use the what() and where() methods to get information about the exception. - */ class PCORE_EXPORT Exception { public: - /** - Creates an exception with the given what() string - and the given SourceInfo. + //! Constructor + /*! + Creates an exception with the given what() string + and the given SourceInfo. The what argument must be a + statically allocated string cause it's only referenced + by the Exception class. + \param what a statically allocated string describing + what happened + \param si the source location where the exception occured. + use P_SOURCEINFO for ease of use. */ Exception(const char* what, const SourceInfo& si) throw(); - /** - Convenience/compatibility overload. - */ - Exception(const std::string & what, const SourceInfo& si) throw(); + //! Copy constructor Exception(const Exception& err) throw(); - ~Exception() throw(); - Exception& operator=(const Exception& err) throw(); + //! Destructor + ~Exception() throw(); - /** - Returns a description of the exception. + //! Returns the cause auf the exception + /*! + Returns a description of what happened. */ const char* what() const throw(); - /** + /*! Returns a string describing where this exception - was thrown. + was thrown. Note that this method may throw. */ - const char * where() const throw(); + std::string where() const; + + //! Assignment operator + Exception& operator=(const Exception& err) throw(); private: - std::string _what; + const char* _what; const SourceInfo* _source; - mutable std::string _where; // really should be a const char *, but that's not practical here w/o malloc()ing. }; +PCORE_EXPORT std::ostream& operator<<(std::ostream& os, const Exception& err); + + //! Logic error +/*! + This exception class is thrown whenever the framework detects + a logical error. For example when you try to start a Thread which + is already running. +*/ class PCORE_EXPORT LogicError: public Exception { public: LogicError(const char* what, const SourceInfo& si) throw(); - LogicError(const std::string & what, const SourceInfo& si) throw(); ~LogicError() throw(); }; @@ -85,39 +103,39 @@ class PCORE_EXPORT RuntimeError: public Exception { public: RuntimeError(const char* what, const SourceInfo& si) throw(); - RuntimeError(const std::string & what, const SourceInfo& si) throw(); ~RuntimeError() throw(); }; class PCORE_EXPORT OverrunError: public RuntimeError { public: OverrunError(const char* what, const SourceInfo& si) throw(); - OverrunError(const std::string & what, const SourceInfo& si) throw(); ~OverrunError() throw(); }; class PCORE_EXPORT UnderrunError: public RuntimeError { public: UnderrunError(const char* what, const SourceInfo& si) throw(); - UnderrunError(const std::string & what, const SourceInfo& si) throw(); - ~UnderrunError() throw(); }; class PCORE_EXPORT OutOfBounds: public RuntimeError { public: OutOfBounds(const char* what, const SourceInfo& si) throw(); - OutOfBounds(const std::string & what, const SourceInfo& si) throw(); ~OutOfBounds() throw(); }; class PCORE_EXPORT OverflowError: public RuntimeError { public: OverflowError(const char* what, const SourceInfo& si) throw(); - OverflowError(const std::string & what, const SourceInfo& si) throw(); ~OverflowError() throw(); }; +class PCORE_EXPORT ConversionError: public RuntimeError { + public: + ConversionError(const char* what, const SourceInfo& si) throw(); + ~ConversionError() throw(); +}; + } //! namespace P #endif |