]>
Commit | Line | Data |
---|---|---|
774c051c | 1 | #ifndef SQUID__TEXTEXCEPTION_H |
2 | #define SQUID__TEXTEXCEPTION_H | |
3 | ||
4 | // Origin: xstd/TextException | |
5 | ||
6 | ||
7 | // simple exception to report custom errors | |
8 | // we may want to change the interface to be able to report system errors | |
9 | ||
0a8bbeeb | 10 | class TextException: public std::exception |
774c051c | 11 | { |
12 | ||
13 | public: | |
14 | TextException(const char *aMessage, const char *aFileName = 0, int aLineNo = -1); | |
0a8bbeeb | 15 | virtual ~TextException() throw(); |
774c051c | 16 | |
0a8bbeeb | 17 | virtual const char *what() const throw(); |
774c051c | 18 | |
19 | public: | |
20 | char *message; // read-only | |
21 | ||
22 | protected: | |
23 | // optional location information | |
24 | const char *theFileName; | |
25 | int theLineNo; | |
26 | }; | |
27 | ||
28 | //inline | |
29 | //ostream &operator <<(ostream &os, const TextException &exx) { | |
c99de607 | 30 | // return exx.print(os); |
774c051c | 31 | //} |
32 | ||
33 | #if !defined(TexcHere) | |
c99de607 | 34 | # define TexcHere(msg) TextException((msg), __FILE__, __LINE__) |
774c051c | 35 | #endif |
36 | ||
37 | extern void Throw(const char *message, const char *fileName, int lineNo); | |
38 | ||
39 | // Must(condition) is like assert(condition) but throws an exception instead | |
40 | #if !defined(Must) | |
c99de607 | 41 | # define Must(cond) ((cond) ? \ |
42 | (void)0 : \ | |
43 | (void)Throw(#cond, __FILE__, __LINE__)) | |
774c051c | 44 | #endif |
45 | ||
46 | #endif /* SQUID__TEXTEXCEPTION_H */ |