[88] | 1 | #ifndef Morpheo_ErrorMorpheo_h |
---|
| 2 | #define Morpheo_ErrorMorpheo_h |
---|
[2] | 3 | |
---|
| 4 | /* |
---|
| 5 | * $Id: ErrorMorpheo.h 146 2011-02-01 20:57:54Z rosiere $ |
---|
| 6 | * |
---|
[71] | 7 | * [ Description ] |
---|
[2] | 8 | * |
---|
| 9 | */ |
---|
| 10 | |
---|
[88] | 11 | #include "Common/include/ToString.h" |
---|
| 12 | #include "Common/include/Translation.h" |
---|
| 13 | #include "Common/include/Message.h" |
---|
| 14 | |
---|
[2] | 15 | #include <iostream> |
---|
| 16 | #include <exception> |
---|
| 17 | |
---|
| 18 | namespace morpheo { |
---|
| 19 | |
---|
[146] | 20 | #define ERRORMORPHEO(funcname,msg) \ |
---|
| 21 | ErrorMorpheo(funcname,msg,__LINE__,__FILE__) |
---|
[71] | 22 | |
---|
[146] | 23 | #define THROW_ERRORMORPHEO(cond,funcname,msg) \ |
---|
| 24 | do \ |
---|
| 25 | { \ |
---|
| 26 | if (cond) \ |
---|
| 27 | { \ |
---|
| 28 | throw ERRORMORPHEO(funcname,msg); \ |
---|
| 29 | } \ |
---|
| 30 | } \ |
---|
| 31 | while (0) |
---|
| 32 | |
---|
[71] | 33 | class ErrorMorpheo : public std::exception |
---|
[2] | 34 | { |
---|
[117] | 35 | // -----[ fields ]---------------------------------------------------- |
---|
[71] | 36 | private : std::string _msg; |
---|
[2] | 37 | |
---|
[117] | 38 | // -----[ methods ]--------------------------------------------------- |
---|
[88] | 39 | public : ErrorMorpheo () throw() {_msg = toString("%s ",MSG_ERROR); _msg+="Exception detected ...";} |
---|
| 40 | public : ErrorMorpheo (std::string msg) throw() {_msg = toString("%s ",MSG_ERROR); _msg+=msg;} |
---|
[71] | 41 | public : ErrorMorpheo (std::string funcname, |
---|
| 42 | std::string msg , |
---|
| 43 | int line , |
---|
| 44 | std::string file ) throw() |
---|
| 45 | { |
---|
[88] | 46 | #ifdef DEBUG |
---|
[136] | 47 | _msg = toString(_("%s at line %d, in file %s"),MSG_ERROR,line,file.c_str()); |
---|
| 48 | _msg = toString(_("%s <%s> %s"),MSG_ERROR,funcname.c_str(),msg.c_str()); |
---|
[88] | 49 | #else |
---|
[136] | 50 | _msg = toString(_("%s %s"),MSG_ERROR,msg.c_str()); |
---|
[88] | 51 | #endif |
---|
[138] | 52 | // msg("%s",_msg.c_str()); |
---|
[71] | 53 | } |
---|
[2] | 54 | public : ~ErrorMorpheo (void) throw() {} |
---|
| 55 | public : const char* what () const throw() { return ( _msg.c_str() );} |
---|
| 56 | |
---|
| 57 | }; |
---|
| 58 | |
---|
| 59 | }; // end namespace morpheo |
---|
| 60 | |
---|
| 61 | #endif |
---|