Update of /cvsroot/pclasses/pclasses2/include/pclasses
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2556/include/pclasses
Modified Files:
Exception.h
Log Message:
added where() method. Had to do a small amount of refactoring.
Index: Exception.h
===================================================================
RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Exception.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- Exception.h 22 Dec 2004 17:54:39 -0000 1.1.1.1
+++ Exception.h 24 Dec 2004 16:48:05 -0000 1.2
@@ -21,24 +21,55 @@
#ifndef _P_Exception_h_
#define _P_Exception_h_
+#include <string>
#include <pclasses/SourceInfo.h>
namespace P {
-//! Exception base class
+/**
+This is the base Exception class for the P framework.
+
+Exception uses a non-traditional ctor, requiring a SourceInfo
+argument. Use the P_SOURCEINFO macro to pass SourceInfo to exceptions:
+
+throw MyException( "dammit!", P_SOURCEINFO );
+
+Clients may use the what() and where() methods to get information
+about the exception.
+
+*/
class Exception {
public:
+ /**
+ Creates an exception with the given what() string
+ and the given SourceInfo.
+ */
Exception(const char* what, const SourceInfo& si) throw();
+ /**
+ Convenience/compatibility overload.
+ */
+ Exception(const std::string & what, const SourceInfo& si) throw();
+
Exception(const Exception& err) throw();
~Exception() throw();
Exception& operator=(const Exception& err) throw();
+ /**
+ Returns a description of the exception.
+ */
const char* what() const throw();
+ /**
+ Returns a string describing where this exception
+ was thrown.
+ */
+ const char * where() const throw();
+
private:
- const char* _what;
+ std::string _what;
const SourceInfo* _source;
+ mutable std::string _where; // really should be a const char *, but that's not practical here w/o malloc()ing.
};
//! Logic error
|