| 35 | namespace util |
| 36 | { |
| 37 | class Error : public std::exception |
| 38 | { |
| 39 | public: |
| 40 | |
| 41 | Error(const char *method_, char *message_) |
| 42 | { |
| 43 | init(method_, message_, -1); |
| 44 | } |
| 45 | |
| 46 | Error(const char *method_, const char *message_) |
| 47 | { |
| 48 | init(method_, (char *)message_, -1); |
| 49 | } |
| 50 | |
| 51 | Error(const char *method_, char *message_, int line) |
| 52 | { |
| 53 | init(method_, message_, line); |
| 54 | } |
| 55 | |
| 56 | Error(const char *method_, const char *message_, int line) |
| 57 | { |
| 58 | init(method_, (char *)message_, line); |
| 59 | } |
| 60 | |
| 61 | void init(const char *method_, char *message_, int line) |
| 62 | { |
| 63 | message[0] = 0; |
| 64 | if(line >= 1) snprintf(message, MLEN + 1, "%d: ", line); |
| 65 | if(!method_) method_ = "(Unknown error location)"; |
| 66 | method = method_; |
| 67 | if(message_) |
| 68 | strncpy(&message[strlen(message)], message_, MLEN - strlen(message)); |
| 69 | } |
| 70 | |
| 71 | Error(void) : method(NULL) { message[0] = 0; } |
| 72 | |
| 73 | operator bool() { return method != NULL && message[0] != 0; } |
| 74 | Error &operator= (const std::exception &e) |
| 75 | { |
| 76 | method = GET_METHOD(e); |
| 77 | strncpy(message, e.what(), MLEN); |
| 78 | return *this; |
| 79 | } |
| 80 | |
| 81 | const char *getMethod(void) { return method; } |
| 82 | virtual const char *what(void) const throw() { return message; } |
| 83 | |
| 84 | protected: |
| 85 | |
| 86 | static const int MLEN = 256; |
| 87 | const char *method; char message[MLEN + 1]; |
| 88 | }; |
| 89 | } |
| 90 | |
| 91 |
no test coverage detected