1 /*=============================================================================
2 Boost.Wave: A Standard compliant C++ preprocessor library
6 Copyright (c) 2001-2012 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 #ifdef BOOST_NO_STRINGSTREAM
23 namespace boost { namespace wave { namespace util
25 #ifdef BOOST_NO_STRINGSTREAM
26 template <typename Exception, typename S1, typename Pos>
27 void throw_(typename Exception::error_code code, S1 msg, Pos const& pos)
29 std::strstream stream;
30 stream << Exception::severity_text(code) << ": "
31 << Exception::error_text(code);
33 stream << ": " << msg;
35 std::string throwmsg = stream.str(); stream.freeze(false);
36 boost::throw_exception(Exception(throwmsg.c_str(), code,
37 pos.get_line(), pos.get_column(), pos.get_file().c_str()));
40 template <typename Exception, typename Context, typename S1, typename Pos>
41 void throw_(Context& ctx, typename Exception::error_code code,
42 S1 msg, Pos const& pos)
44 std::strstream stream;
45 stream << Exception::severity_text(code) << ": "
46 << Exception::error_text(code);
48 stream << ": " << msg;
50 std::string throwmsg = stream.str(); stream.freeze(false);
51 ctx.get_hooks().throw_exception(ctx.derived(),
52 Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(),
53 pos.get_file().c_str()));
56 template <typename Exception, typename S1, typename Pos, typename S2>
57 void throw_(typename Exception::error_code code, S1 msg, Pos const& pos,
60 std::strstream stream;
61 stream << Exception::severity_text(code) << ": "
62 << Exception::error_text(code);
64 stream << ": " << msg;
66 std::string throwmsg = stream.str(); stream.freeze(false);
67 boost::throw_exception(Exception(throwmsg.c_str(), code,
68 pos.get_line(), pos.get_column(), pos.get_file().c_str(), name));
71 template <typename Exception, typename Context, typename S1, typename Pos,
73 void throw_(Context& ctx, typename Exception::error_code code,
74 S1 msg, Pos const& pos, S2 name)
76 std::strstream stream;
77 stream << Exception::severity_text(code) << ": "
78 << Exception::error_text(code);
80 stream << ": " << msg;
82 std::string throwmsg = stream.str(); stream.freeze(false);
83 ctx.get_hooks().throw_exception(ctx.derived(),
84 Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(),
85 pos.get_file().c_str(), name));
88 template <typename Exception, typename S1, typename Pos>
89 void throw_(typename Exception::error_code code, S1 msg, Pos const& pos)
91 std::stringstream stream;
92 stream << Exception::severity_text(code) << ": "
93 << Exception::error_text(code);
95 stream << ": " << msg;
97 std::string throwmsg = stream.str();
98 boost::throw_exception(Exception(throwmsg.c_str(), code,
99 pos.get_line(), pos.get_column(), pos.get_file().c_str()));
102 template <typename Exception, typename Context, typename S1, typename Pos>
103 void throw_(Context& ctx, typename Exception::error_code code,
104 S1 msg, Pos const& pos)
106 std::stringstream stream;
107 stream << Exception::severity_text(code) << ": "
108 << Exception::error_text(code);
110 stream << ": " << msg;
112 std::string throwmsg = stream.str();
113 ctx.get_hooks().throw_exception(ctx.derived(),
114 Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(),
115 pos.get_file().c_str()));
118 template <typename Exception, typename S1, typename Pos, typename S2>
119 void throw_(typename Exception::error_code code, S1 msg, Pos const& pos,
122 std::stringstream stream;
123 stream << Exception::severity_text(code) << ": "
124 << Exception::error_text(code);
126 stream << ": " << msg;
128 std::string throwmsg = stream.str();
129 boost::throw_exception(Exception(throwmsg.c_str(), code,
130 pos.get_line(), pos.get_column(), pos.get_file().c_str(), name));
133 template <typename Exception, typename Context, typename S1, typename Pos1,
135 void throw_(Context& ctx, typename Exception::error_code code,
136 S1 msg, Pos1 const& pos, S2 name)
138 std::stringstream stream;
139 stream << Exception::severity_text(code) << ": "
140 << Exception::error_text(code);
142 stream << ": " << msg;
144 std::string throwmsg = stream.str();
145 ctx.get_hooks().throw_exception(ctx.derived(),
146 Exception(throwmsg.c_str(), code, pos.get_line(), pos.get_column(),
147 pos.get_file().c_str(), name));
152 ///////////////////////////////////////////////////////////////////////////////
153 // helper macro for throwing exceptions
154 #if !defined(BOOST_WAVE_THROW)
155 #define BOOST_WAVE_THROW(cls, code, msg, act_pos) \
156 boost::wave::util::throw_<cls>(cls::code, msg, act_pos) \
159 #define BOOST_WAVE_THROW_CTX(ctx, cls, code, msg, act_pos) \
160 boost::wave::util::throw_<cls>(ctx, cls::code, msg, act_pos) \
162 #endif // BOOST_WAVE_THROW
164 ///////////////////////////////////////////////////////////////////////////////
165 // helper macro for throwing exceptions with additional parameter
166 #if !defined(BOOST_WAVE_THROW_NAME_CTX)
167 #define BOOST_WAVE_THROW_NAME_CTX(ctx, cls, code, msg, act_pos, name) \
168 boost::wave::util::throw_<cls>(cls::code, msg, act_pos, name) \
170 #endif // BOOST_WAVE_THROW_NAME_CTX
172 ///////////////////////////////////////////////////////////////////////////////
173 // helper macro for throwing exceptions with additional parameter
174 #if !defined(BOOST_WAVE_THROW_VAR_CTX)
175 #define BOOST_WAVE_THROW_VAR_CTX(ctx, cls, code, msg, act_pos) \
176 boost::wave::util::throw_<cls>(ctx, code, msg, act_pos) \
178 #endif // BOOST_WAVE_THROW_VAR_CTX
180 #endif // !defined(BOOST_WAVE_CPP_THROW_HPP_INCLUDED)