]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/base/TextException.cc
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
10 #include "base/TextException.h"
12 #include "sbuf/SBuf.h"
15 TextException::TextException()
23 TextException::TextException(const TextException
& right
) :
24 message((right
.message
?xstrdup(right
.message
):NULL
)), theFileName(right
.theFileName
), theLineNo(right
.theLineNo
), theId(right
.theId
)
28 TextException::TextException(const char *aMsg
, const char *aFileName
, int aLineNo
, unsigned int anId
):
29 message(aMsg
?xstrdup(aMsg
):NULL
), theFileName(aFileName
), theLineNo(aLineNo
), theId(anId
)
32 TextException::TextException(SBuf msg
, const char *aFileName
, int aLineNo
, unsigned int anId
):
33 TextException(msg
.c_str(), aFileName
, aLineNo
, anId
)
36 TextException::~TextException() throw()
38 if (message
) xfree(message
);
41 TextException
& TextException::operator=(const TextException
&right
)
43 if (this==&right
) return *this;
44 if (message
) xfree(message
);
45 message
=(right
.message
?xstrdup(right
.message
):NULL
);
46 theFileName
=right
.theFileName
;
47 theLineNo
=right
.theLineNo
;
52 const char *TextException::what() const throw()
54 /// \todo add file:lineno
55 return message
? message
: "TextException without a message";
58 unsigned int TextException::FileNameHash(const char *fname
)
64 s
= strrchr(fname
, '/');
73 n
^= 271 * (unsigned) *s
;
77 /*18bits of a 32 bit integer used for filename hash (max hash=262143),
78 and 14 bits for storing line number (16k max).
79 If you change this policy remember to update the FileNameHash function
80 in the scripts/calc-must-ids.pl script
85 void Throw(const char *message
, const char *fileName
, int lineNo
, unsigned int id
)
88 // or should we let the exception recepient print the exception instead?
91 debugs(0, 3, fileName
<< ':' << lineNo
<< ": exception" <<
92 (message
? ": " : ".") << (message
? message
: ""));
94 debugs(0, 3, "exception" <<
95 (message
? ": " : ".") << (message
? message
: ""));
98 throw TextException(message
, fileName
, lineNo
, id
);