1 /*=============================================================================
2 Boost.Wave: A Standard compliant C++ preprocessor library
6 Copyright (c) 2001-2009 Hartmut Kaiser. Distributed under the Boost
7 Software License, Version 1.0. (See accompanying file
8 LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 =============================================================================*/
11 #if !defined(BOOST_WAVE_CPP_THROW_HPP_INCLUDED)
12 #define BOOST_WAVE_CPP_THROW_HPP_INCLUDED
15 #include <boost/throw_exception.hpp>
17 ///////////////////////////////////////////////////////////////////////////////
18 // helper macro for throwing exceptions
19 #if !defined(BOOST_WAVE_THROW)
20 #ifdef BOOST_NO_STRINGSTREAM
22 #define BOOST_WAVE_THROW(cls, code, msg, act_pos) \
24 using namespace boost::wave; \
25 std::strstream stream; \
26 stream << cls::severity_text(cls::code) << ": " \
27 << cls::error_text(cls::code); \
28 if ((msg)[0] != 0) stream << ": " << (msg); \
29 stream << std::ends; \
30 std::string throwmsg = stream.str(); stream.freeze(false); \
31 boost::throw_exception(cls(throwmsg.c_str(), cls::code, \
32 (act_pos).get_line(), (act_pos).get_column(), \
33 (act_pos).get_file().c_str())); \
36 #define BOOST_WAVE_THROW_CTX(ctx, cls, code, msg, act_pos) \
38 using namespace boost::wave; \
39 std::strstream stream; \
40 stream << cls::severity_text(cls::code) << ": " \
41 << cls::error_text(cls::code); \
42 if ((msg)[0] != 0) stream << ": " << (msg); \
43 stream << std::ends; \
44 std::string throwmsg = stream.str(); stream.freeze(false); \
45 ctx.get_hooks().throw_exception(ctx.derived(), cls(throwmsg.c_str(), \
46 cls::code, (act_pos).get_line(), (act_pos).get_column(), \
47 (act_pos).get_file().c_str())); \
52 #define BOOST_WAVE_THROW(cls, code, msg, act_pos) \
54 using namespace boost::wave; \
55 std::stringstream stream; \
56 stream << cls::severity_text(cls::code) << ": " \
57 << cls::error_text(cls::code); \
58 if ((msg)[0] != 0) stream << ": " << (msg); \
59 stream << std::ends; \
60 boost::throw_exception(cls(stream.str().c_str(), cls::code, \
61 (act_pos).get_line(), (act_pos).get_column(), \
62 (act_pos).get_file().c_str())); \
65 #define BOOST_WAVE_THROW_CTX(ctx, cls, code, msg, act_pos) \
67 using namespace boost::wave; \
68 std::stringstream stream; \
69 stream << cls::severity_text(cls::code) << ": " \
70 << cls::error_text(cls::code); \
71 if ((msg)[0] != 0) stream << ": " << (msg); \
72 stream << std::ends; \
73 ctx.get_hooks().throw_exception(ctx.derived(), \
74 cls(stream.str().c_str(), cls::code, (act_pos).get_line(), \
75 (act_pos).get_column(), (act_pos).get_file().c_str())); \
78 #endif // BOOST_NO_STRINGSTREAM
79 #endif // BOOST_WAVE_THROW
81 ///////////////////////////////////////////////////////////////////////////////
82 // helper macro for throwing exceptions with additional parameter
83 #if !defined(BOOST_WAVE_THROW_NAME)
84 #ifdef BOOST_NO_STRINGSTREAM
86 #define BOOST_WAVE_THROW_NAME_CTX(ctx, cls, code, msg, act_pos, name) \
88 using namespace boost::wave; \
89 std::strstream stream; \
90 stream << cls::severity_text(cls::code) << ": " \
91 << cls::error_text(cls::code); \
92 if ((msg)[0] != 0) stream << ": " << (msg); \
93 stream << std::ends; \
94 std::string throwmsg = stream.str(); stream.freeze(false); \
95 ctx.get_hooks().throw_exception(ctx.derived(), cls(throwmsg.c_str(), \
96 cls::code, (act_pos).get_line(), (act_pos).get_column(), \
97 (act_pos).get_file().c_str(), (name))); \
102 #define BOOST_WAVE_THROW_NAME_CTX(ctx, cls, code, msg, act_pos, name) \
104 using namespace boost::wave; \
105 std::stringstream stream; \
106 stream << cls::severity_text(cls::code) << ": " \
107 << cls::error_text(cls::code); \
108 if ((msg)[0] != 0) stream << ": " << (msg); \
109 stream << std::ends; \
110 ctx.get_hooks().throw_exception(ctx.derived(), \
111 cls(stream.str().c_str(), cls::code, (act_pos).get_line(), \
112 (act_pos).get_column(), (act_pos).get_file().c_str(), (name))); \
115 #endif // BOOST_NO_STRINGSTREAM
116 #endif // BOOST_WAVE_THROW_NAME
118 ///////////////////////////////////////////////////////////////////////////////
119 // helper macro for throwing exceptions with additional parameter
120 #if !defined(BOOST_WAVE_THROW_VAR)
121 #ifdef BOOST_NO_STRINGSTREAM
123 #define BOOST_WAVE_THROW_VAR_CTX(ctx, cls, code, msg, act_pos) \
125 using namespace boost::wave; \
126 std::strstream stream; \
127 stream << cls::severity_text(code) << ": " \
128 << cls::error_text(code); \
129 if ((msg)[0] != 0) stream << ": " << (msg); \
130 stream << std::ends; \
131 std::string throwmsg = stream.str(); stream.freeze(false); \
132 ctx.get_hooks().throw_exception(ctx.derived(), cls(throwmsg.c_str(), \
133 code, (act_pos).get_line(), (act_pos).get_column(), \
134 (act_pos).get_file().c_str())); \
139 #define BOOST_WAVE_THROW_VAR_CTX(ctx, cls, code, msg, act_pos) \
141 using namespace boost::wave; \
142 std::stringstream stream; \
143 stream << cls::severity_text(code) << ": " \
144 << cls::error_text(code); \
145 if ((msg)[0] != 0) stream << ": " << (msg); \
146 stream << std::ends; \
147 ctx.get_hooks().throw_exception(ctx.derived(), \
148 cls(stream.str().c_str(), code, (act_pos).get_line(), \
149 (act_pos).get_column(), (act_pos).get_file().c_str())); \
152 #endif // BOOST_NO_STRINGSTREAM
153 #endif // BOOST_WAVE_THROW_VAR
155 #endif // !defined(BOOST_WAVE_CPP_THROW_HPP_INCLUDED)