Branch data Line data Source code
1 : : // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
2 : : //
3 : : // Permission to use, copy, modify, and/or distribute this software for any
4 : : // purpose with or without fee is hereby granted, provided that the above
5 : : // copyright notice and this permission notice appear in all copies.
6 : : //
7 : : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
8 : : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9 : : // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
10 : : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11 : : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
12 : : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13 : : // PERFORMANCE OF THIS SOFTWARE.
14 : :
15 : : #ifndef __MESSAGE_EXCEPTION_H
16 : : #define __MESSAGE_EXCEPTION_H
17 : :
18 : : #include <exceptions/exceptions.h>
19 : : #include <log/message_types.h>
20 : :
21 : : #include <stdexcept>
22 : : #include <string>
23 : : #include <vector>
24 : :
25 : : #include <boost/lexical_cast.hpp>
26 : :
27 : : namespace isc {
28 : : namespace log {
29 : :
30 : : /// \brief Message Exception
31 : : ///
32 : : /// Used in the message reader, this simple exception class allows a message
33 : : /// code and its arguments to be encapsulated in an exception and thrown
34 : : /// up the stack.
35 : :
36 : : class MessageException : public isc::Exception {
37 : : public:
38 : :
39 : : /// \brief Constructor
40 : : ///
41 : : /// \param id Message identification.
42 : : /// \param lineno Line number on which error occurred (if > 0).
43 : 4 : MessageException(const char* file, size_t line, const char* what,
44 : : MessageID id, int lineno)
45 : 4 : : isc::Exception(file, line, what), id_(id), lineno_(lineno)
46 : : {
47 [ - + ]: 4 : if (lineno_ > 0) {
48 [ # # ]: 0 : args_.push_back(boost::lexical_cast<std::string>(lineno));
49 : : }
50 : 4 : }
51 : :
52 : : /// \brief Constructor
53 : : ///
54 : : /// \param id Message identification.
55 : : /// \param arg1 First message argument.
56 : : /// \param lineno Line number on which error occurred (if > 0).
57 : 7 : MessageException(const char* file, size_t line, const char* what,
58 : : MessageID id, const std::string& arg1, int lineno)
59 : 7 : : isc::Exception(file, line, what), id_(id)
60 : : {
61 [ - + ]: 7 : if (lineno > 0) {
62 [ # # ]: 0 : args_.push_back(boost::lexical_cast<std::string>(lineno));
63 : : }
64 [ + - ]: 7 : args_.push_back(arg1);
65 : 7 : }
66 : :
67 : : /// \brief Constructor
68 : : ///
69 : : /// \param id Message identification.
70 : : /// \param arg1 First message argument.
71 : : /// \param arg2 Second message argument.
72 : : /// \param lineno Line number on which error occurred (if > 0).
73 : 2 : MessageException(const char* file, size_t line, const char *what,
74 : : MessageID id, const std::string& arg1,
75 : : const std::string& arg2, int lineno)
76 : 2 : : isc::Exception(file, line, what), id_(id)
77 : : {
78 [ - + ]: 2 : if (lineno > 0) {
79 [ # # ]: 0 : args_.push_back(boost::lexical_cast<std::string>(lineno));
80 : : }
81 [ + - ]: 2 : args_.push_back(arg1);
82 [ + - ]: 2 : args_.push_back(arg2);
83 : 2 : }
84 : :
85 : : /// \brief Destructor
86 : 13 : ~MessageException() throw() {}
87 : :
88 : : /// \brief Return Message ID
89 : : ///
90 : : /// \return Message identification
91 : 0 : MessageID id() const {
92 : 0 : return id_;
93 : : }
94 : :
95 : : /// \brief Return Arguments
96 : : ///
97 : : /// \return Exception Arguments
98 : : std::vector<std::string> arguments() const {
99 [ - + ]: 2 : return (args_);
100 : : }
101 : :
102 : : private:
103 : : MessageID id_; // Exception ID
104 : : std::vector<std::string> args_; // Exception arguments
105 : : int lineno_;
106 : : };
107 : :
108 : : } // namespace log
109 : : } // namespace isc
110 : :
111 : : #endif // __MESSAGE_EXCEPTION_H
|