]> git.ipfire.org Git - thirdparty/squid.git/blob - src/base/TextException.cc
Merged from trunk
[thirdparty/squid.git] / src / base / TextException.cc
1 #include "config.h"
2 #include "base/TextException.h"
3 #include "Debug.h"
4 #include "util.h"
5
6 TextException::TextException()
7 {
8 message=NULL;
9 theFileName=NULL;
10 theLineNo=0;
11 }
12
13 TextException::TextException(const TextException& right) :
14 message((right.message?xstrdup(right.message):NULL)), theFileName(right.theFileName), theLineNo(right.theLineNo)
15 {
16 }
17
18 TextException::TextException(const char *aMsg, const char *aFileName, int aLineNo):
19 message(xstrdup(aMsg)), theFileName(aFileName), theLineNo(aLineNo)
20 {}
21
22 TextException::~TextException() throw()
23 {
24 if (message) xfree(message);
25 }
26
27 TextException& TextException::operator=(const TextException &right)
28 {
29 if (this==&right) return *this;
30 if (message) xfree(message);
31 message=(right.message?xstrdup(right.message):NULL);
32 theFileName=right.theFileName;
33 theLineNo=right.theLineNo;
34
35 return *this;
36 }
37
38 const char *TextException::what() const throw()
39 {
40 /// \todo add file:lineno
41 return message ? message : "TextException without a message";
42 }
43
44 void Throw(const char *message, const char *fileName, int lineNo)
45 {
46
47 // or should we let the exception recepient print the exception instead?
48
49 if (fileName) {
50 debugs(0, 3, fileName << ':' << lineNo << ": exception" <<
51 (message ? ": " : ".") << (message ? message : ""));
52 } else {
53 debugs(0, 3, "exception" <<
54 (message ? ": " : ".") << (message ? message : ""));
55 }
56
57 throw TextException(message, fileName, lineNo);
58 }