#ifndef AMMASTDERROR_HEADER #define AMMASTDERROR_HEADER 1 ////////////////////////////////////////////////////////// //! userlevel=Normal //! docentry="Basic Types.Exceptions" //! lib=Mtype //! rcsid="$Id: StdError.hh,v 1.12 2000/07/14 13:23:18 ees1cg Exp $" //! file="amma/BasType/StdError.hh" //! author="Charles Galambos" //! date="05/07/98" #include "amma/Config.hh" #if USE_STDCPP_TYPEINFO_H #include //#include #endif #if USE_STDCPP_TYPEINFO #include //#include #endif //: General Error. // Base class for AMMA's error exceptions. class ExceptionC { public: ExceptionC(const char *ntext) : desc(ntext), ref(false) {} //: Constructor ExceptionC(const char *ntext,bool copy); //: Constructor. // Copy string if 'copy' is true. ExceptionC(const ExceptionC &oth) : desc(oth.desc), ref(oth.ref) { if(oth.ref) const_cast(oth).ref = false; } //: Copy Constructor // This assumes the only time you use a copy constructor // on an exception is when passing it as an argument! virtual ~ExceptionC() { if(ref) delete (char *)desc; } //: Virtualise destructor. const char *Text() const { return desc; } //: Get error description. virtual void Dump(); //: Dump contents of exception to cerr; const char *what() const { return desc; } //: Standard exception text message. protected: const char *desc; bool ref; // Delete string in constructor ? }; //: Casting exception class. // Throw if illegal cast is attempted. class ErrorCastC : public ExceptionC { public: ErrorCastC(const char *ndesc,const type_info &nfrom,const type_info &nto) : ExceptionC(ndesc), from(nfrom), to(nto) {} //: Constructor. const type_info &From() const { return from; } //: Cast from. const type_info &To() const { return to; } //: Cast to. virtual void Dump(); //: Dump contents of exception to cerr; protected: const type_info &from; const type_info &to; }; //: Exception: Out of range. // Thrown if illegal value is attempted with an operation. class ErrorOutOfRangeC : public ExceptionC { public: ErrorOutOfRangeC(const char *ndesc) : ExceptionC(ndesc) {} //: Constructor. }; //: Exception: Out of range. // Thrown if a requested operation failed because of // conditions outside the programs control. (Such as running // out of disk space.) class ErrorOperationFailedC : public ExceptionC { public: ErrorOperationFailedC(const char *ndesc) : ExceptionC(ndesc) {} //: Constructor. ErrorOperationFailedC(const char *ntext,bool copy) : ExceptionC(ntext,copy) {} //: Constructor. // if copy is true, a copy is made of string ntext. }; //: Exit program with message and return code. class ExceptionExitC : public ExceptionC { public: ExceptionExitC(int ncode,const char *ndesc) : ExceptionC(ndesc), code(ncode) {} //: Constructor. ExceptionExitC(int ncode,const char *ntext,bool copy) : ExceptionC(ntext,copy), code(ncode) {} //: Constructor. // if copy is true, a copy is made of string ntext. inline int Code() { return code; } //: Desired exit code. protected: int code; }; //: Report an unimplemented function. // If in check mode constructor will abort to make it // easy to find with a stack trace. class ErrorNotImplementedC : public ExceptionC { public: ErrorNotImplementedC(const char *ntext); //: Constructor ErrorNotImplementedC(const char *ntext,bool copy); //: Constructor. // Copy string if 'copy' is true. }; #endif