]> git.ipfire.org Git - thirdparty/squid.git/blame - src/TextException.cc
SourceFormat: enforcement
[thirdparty/squid.git] / src / TextException.cc
CommitLineData
774c051c 1#include "squid.h"
2#include "TextException.h"
3
77442705
AJ
4TextException::TextException()
5{
e1381638
AJ
6 message=NULL;
7 theFileName=NULL;
8 theLineNo=0;
77442705
AJ
9}
10
11TextException::TextException(const TextException& right) :
e1381638 12 message((right.message?xstrdup(right.message):NULL)), theFileName(right.theFileName), theLineNo(right.theLineNo)
77442705
AJ
13{
14}
15
774c051c 16TextException::TextException(const char *aMsg, const char *aFileName, int aLineNo):
17 message(xstrdup(aMsg)), theFileName(aFileName), theLineNo(aLineNo)
18{}
19
0a8bbeeb 20TextException::~TextException() throw()
774c051c 21{
e1381638 22 if (message) xfree(message);
77442705
AJ
23}
24
25TextException& TextException::operator=(const TextException &right)
26{
e1381638
AJ
27 if (this==&right) return *this;
28 if (message) xfree(message);
77442705
AJ
29 message=(right.message?xstrdup(right.message):NULL);
30 theFileName=right.theFileName;
31 theLineNo=right.theLineNo;
32
e1381638 33 return *this;
774c051c 34}
35
0a8bbeeb
AR
36const char *TextException::what() const throw()
37{
38 /// \todo add file:lineno
39 return message ? message : "TextException without a message";
40}
41
774c051c 42void 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}