/** * $Id: exception.h,v 1.17 2002/10/22 14:01:08 plasmahh Exp $ * $Revision: 1.17 $ * $Author: plasmahh $ * $Date: 2002/10/22 14:01:08 $ */ #ifndef __EXCEPTION_H #define __EXCEPTION_H #ifndef __MSTRING_H #include "mstring.h" #endif /** * Base class for all exceptions */ class Exception/*{{{*/ { protected: bool hand; mstring exception; mstring where; mstring code; int line; mstring file; mstring detail; public: Exception():hand(false) { } Exception(mstring w, mstring c, int l, mstring f, mstring d) : hand(false), where(w), code(c), line(l), file(f), detail(d){ } virtual ~Exception() { show(); } inline void show ( void ); inline void handled( void ) { hand = true; } };/*}}}*/ inline void Exception::show( void )/*{{{*/ { if (hand) return; cout << "Exception occured : " << exception << endl; cout << "why : " << where << endl; cout << "at : " << code << endl; cout << "in file : " << file << ", line " << line << endl; cout << "handled : " << ((hand) ? "yes" : "no") << endl; cout << "details : " << detail << endl; hand = true; }/*}}}*/ class x_mem : public Exception/*{{{*/ { public: x_mem(mstring w, mstring c, int l, mstring f) : Exception(w,c,l,f,"The program tried to allocate memory, but the system wasn't able to get some" ){ exception = "Memory Allocation";} x_mem(mstring w, mstring c) : Exception(w,c,0," ","The program tried to allocate memory, but the system wasn't able to get some" ){ exception = "Memory Allocation";} virtual ~x_mem(){} };/*}}}*/ class x_implemented : public Exception/*{{{*/ { public: x_implemented (mstring w, mstring c, int l, mstring f) : Exception(w,c,l,f,"The program was asked for a function, but this has not (yet) been fully implemented"){exception = "Not Yet Implemented"; } x_implemented (mstring w, mstring c) : Exception(w,c,0,"","The program was asked for a function, but this has not (yet) been fully implemented"){exception = "Not Yet Implemented"; } virtual ~x_implemented(){} };/*}}}*/ class x_math : public Exception/*{{{*/ { public: x_math (mstring w, mstring c, int l, mstring f) : Exception(w,c,l,f,"Generic Mathematic exception"){exception = "Math Exception";} x_math (mstring w, mstring c) : Exception(w,c,0,"","Generic Mathematix exception"){exception = "Math Exception"; } virtual ~x_math(){ } };/*}}}*/ class x_key : public Exception/*{{{*/ { public: x_key (mstring w, mstring c, int l, mstring f) : Exception(w,c,l,f,"Key Violation/Key not found"){exception = "Key Exception";} x_key (mstring w, mstring c) : Exception(w,c,0,"","Key Violation/Key not found"){exception = "Key Exception"; } virtual ~x_key(){ } };/*}}}*/ class x_parameter : public Exception/*{{{*/ { public: x_parameter (mstring w, mstring c, int l, mstring f) : Exception(w,c,l,f,"One or more parameters were not of the expected values/types"){ exception = "Invalid Parameter"; } x_parameter (mstring w, mstring c ) : Exception(w,c,0,"","One or more parameters were not of the expected values/types"){ exception = "Invalid Parameter"; } virtual ~x_parameter(){ } };/*}}}*/ class x_size : public x_parameter/*{{{*/ { public: x_size(mstring w, mstring c, int l, mstring f) : x_parameter(w,c,l,f) { detail = "A data structure, specified as a paramter was not of the expected size"; exception="Invalid Parameter Size";} x_size(mstring w, mstring c) : x_parameter(w,c,0,"") {detail = "A data structure, specified as a paramter was not of the expected size"; exception = "Invalid Parameter Size";} virtual ~x_size(){} };/*}}}*/ /** * A Parameter for a mathematical computation is not of the right type, or does not have the right size. * Or the values are out of bound. */ class x_mathparam : public x_math/*{{{*/ { public: x_mathparam (mstring w, mstring c, int l, mstring f) : x_math(w,c,l,f) { x_math::detail = "A Parameter for a computation has wrong structure/value/type"; x_math::exception = "Wrong Math-Parameter"; } //x_parameter::handled(); } x_mathparam (mstring w, mstring c) : x_math(w,c,0,"") { x_math::detail = "A Parameter for a computation has wrong structure/value/type"; x_math::exception = "Wrong Math-Parameter"; }// x_parameter::handled();} virtual ~x_mathparam(){ } };/*}}}*/ class x_dimensions : public x_mathparam /*{{{*/ { public: x_dimensions(mstring w, mstring c, int l, mstring f) : x_mathparam(w,c,l,f) { x_math::detail = "The Dimensions do not match for desired computation"; x_math::exception="Matrix Dimensions"; } x_dimensions(mstring w, mstring c) : x_mathparam(w,c,0,"") { x_math::detail = "The Dimensions do not match for desired computation"; x_math::exception="Matrix Dimensions"; } virtual ~x_dimensions(){ } };/*}}}*/ /* c/p this class x_ : virtual public x_ { public: x_(mstring w, mstring c, int l, mstring f) : x_(w,c,l,f) { detail = ""; exception="";} x_(mstring w, mstring c) : x_(w,c,0,"") { detail = ""; exception="";} virtual ~x_(){} }; */ /** * This is the parse exception. Do we need to derive from x_parameter, or is it generic exception ? * It is some kind of wrong parameter if we can't parse, but its also a bit too generic * in case of things like reading from a file... */ class x_parse : public x_parameter /*{{{*/ { public: x_parse(mstring w, mstring c, int l, mstring f) : x_parameter(w,c,l,f) { detail = "An error occured, while parsing a parameter"; exception="Generic Parsing error";} x_parse(mstring w, mstring c) : x_parameter(w,c,0,"") { detail = "An error occured, while parsing a parameter"; exception="Generic Parsing error";} virtual ~x_parse() { } };/*}}}*/ /** * @brief Exception thrown if a invalid character/string was encountered * * Don't use this if char is a possible value, but not in this context * Use something like x_format instead */ class x_invalid_char : public x_parse /*{{{*/ { public: x_invalid_char(mstring w, mstring c, int l, mstring f) : x_parse(w,c,l,f) { detail = "While parsing, we encountered (an) invalid char(s) "; exception="Invalid Character(s) in Parsing";} x_invalid_char(mstring w, mstring c) : x_parse(w,c,0,"") { detail = "While parsing, we encountered (an) invalid char(s) "; exception="Invalid Character(s) in Parsing";} virtual ~x_invalid_char(){} };/*}}}*/ class x_format : public x_parse/*{{{*/ { public: x_format(mstring w, mstring c, int l, mstring f) : x_parse(w,c,l,f) { detail = "While parsing, we encountered error(s) in the format of the input data"; exception="Invalid Format in Parsing";} x_format(mstring w, mstring c) : x_parse(w,c,0,"") { detail = "While parsing, we encountered error(s) in the format of the input data"; exception="Invalid Format in Parsing";} virtual ~x_format(){} };/*}}}*/ class x_com : public Exception/*{{{*/ { public: x_com(mstring w, mstring c, int l, mstring f) : Exception(w,c,l,f,"An Error Occured during communication") { exception="Communication Error";} x_com(mstring w, mstring c) : Exception(w,c,0,"","An Error Occured during communication") { exception="Communication Error";} virtual ~x_com() {} };/*}}}*/ /** * @brief Disconnection exception * * This exception will be used whenever a disconnect was detected, wheter in a write, read or even a connect. * The connect should throw a more detailed version of disconnect, like conn_fail or more detailed... */ class x_disconnect : public x_com/*{{{*/ { public: x_disconnect(mstring w, mstring c, int l, mstring f) : x_com(w,c,l,f) { detail = "A Disconnection State was detected during an communication."; exception="Disconnected";} x_disconnect(mstring w, mstring c) : x_com(w,c,0,"") { detail = "A Disconnection State was detected during an communication."; exception="Disconnected";} ~x_disconnect() {} };/*}}}*/ /** * @brief Connection failure exception * * This Exception will be used whenever a Connect try fails to connect to some host * To catch only by reason, use future exception derived from this */ /* class x_conn_fail : virtual public x_disconnect { }; class x_conn_refuse : virtual public x_conn_fail { }; class x_conn_timeout : virtual public x_conn_fail { }: class x_conn_noroute : virtual public x_conn_fail { }; class x_conn_nohost : virtual public x_conn_fail { }; */ #else #warning Multiple inclusion of exception.h please check your includes #endif /** *$Log: exception.h,v $ *Revision 1.17 2002/10/22 14:01:08 plasmahh *implementing binary tree * *Revision 1.16 2002/10/16 23:07:21 plasmahh *fixed memory bugs in mstring *TODO : refine of exception structure * *Revision 1.15 2002/10/01 21:06:24 plasmahh *new math things * *Revision 1.14 2002/06/17 12:21:03 plasmahh *new exceptions for the future... * *Revision 1.13 2002/06/11 21:16:38 plasmahh *fixed the errors iceblox produced ;) * *Revision 1.12 2002/06/11 21:13:03 iceblox *Fixed some lingual errors and hopefully didn't produce any other errors * *Revision 1.11 2002/06/11 20:44:53 plasmahh *removed exception messages for releases * *Revision 1.10 2002/06/10 22:10:54 plasmahh * added operators and fixed some sorting things * *Revision 1.9 2002/06/10 10:54:41 plasmahh *removed some newlines to avoid compiler warnings (still not run on solaris, since the new iostream seems to be broken there) * *Revision 1.8 2002/05/28 18:47:40 plasmahh *added more or less safe format function to the mstring class *introduced a parser class *some new cool exceptions * *Revision 1.7 2002/05/13 12:58:47 plasmahh *Some improvements and missing implementations * *Revision 1.6 2002/05/05 20:24:36 plasmahh *added doygen configuration file *made dllist work *added dlliterator to dllist.h *made some test progams cooler ;) *added some exceptions... *anything else to do ?? *G* * *Revision 1.5 2002/05/01 20:13:23 plasmahh *made interface to socket a bit easier for simple use *added connection exception * *Revision 1.4 2002/04/30 21:35:17 plasmahh *first working exceptions *first working strings, not everything implemented, should also be tested ! * *Revision 1.3 2002/04/30 19:34:06 plasmahh *fixed segfault with new gcc/g++ compilers * *Revision 1.2 2002/04/29 18:57:10 plasmahh *humm... * *Revision 1.1 2002/04/29 18:51:29 plasmahh *Renamed string to mstring in order to avoid conflicts with standard libraries * */