]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/base/TextException.cc
2 * Copyright (C) 1996-2015 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"
14 TextException::TextException()
22 TextException::TextException(const TextException
& right
) :
23 message((right
.message
?xstrdup(right
.message
):NULL
)), theFileName(right
.theFileName
), theLineNo(right
.theLineNo
), theId(right
.theId
)
27 TextException::TextException(const char *aMsg
, const char *aFileName
, int aLineNo
, unsigned int anId
):
28 message(aMsg
?xstrdup(aMsg
):NULL
), theFileName(aFileName
), theLineNo(aLineNo
), theId(anId
)
31 TextException::~TextException() throw()
33 if (message
) xfree(message
);
36 TextException
& TextException::operator=(const TextException
&right
)
38 if (this==&right
) return *this;
39 if (message
) xfree(message
);
40 message
=(right
.message
?xstrdup(right
.message
):NULL
);
41 theFileName
=right
.theFileName
;
42 theLineNo
=right
.theLineNo
;
47 const char *TextException::what() const throw()
49 /// \todo add file:lineno
50 return message
? message
: "TextException without a message";
53 unsigned int TextException::FileNameHash(const char *fname
)
59 s
= strrchr(fname
, '/');
68 n
^= 271 * (unsigned) *s
;
72 /*18bits of a 32 bit integer used for filename hash (max hash=262143),
73 and 14 bits for storing line number (16k max).
74 If you change this policy remember to update the FileNameHash function
75 in the scripts/calc-must-ids.pl script
80 void Throw(const char *message
, const char *fileName
, int lineNo
, unsigned int id
)
83 // or should we let the exception recepient print the exception instead?
86 debugs(0, 3, fileName
<< ':' << lineNo
<< ": exception" <<
87 (message
? ": " : ".") << (message
? message
: ""));
89 debugs(0, 3, "exception" <<
90 (message
? ": " : ".") << (message
? message
: ""));
93 throw TextException(message
, fileName
, lineNo
, id
);