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