fix doc example typo
[boost.git] / boost / wave / cpp_throw.hpp
blobf2775349fb2589c614c506645497e30058ee18db
1 /*=============================================================================
2 Boost.Wave: A Standard compliant C++ preprocessor library
4 http://www.boost.org/
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
14 #include <string>
15 #include <boost/throw_exception.hpp>
17 ///////////////////////////////////////////////////////////////////////////////
18 // helper macro for throwing exceptions
19 #if !defined(BOOST_WAVE_THROW)
20 #ifdef BOOST_NO_STRINGSTREAM
21 #include <strstream>
22 #define BOOST_WAVE_THROW(cls, code, msg, act_pos) \
23 { \
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())); \
34 } \
35 /**/
36 #define BOOST_WAVE_THROW_CTX(ctx, cls, code, msg, act_pos) \
37 { \
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())); \
48 } \
49 /**/
50 #else
51 #include <sstream>
52 #define BOOST_WAVE_THROW(cls, code, msg, act_pos) \
53 { \
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())); \
63 } \
64 /**/
65 #define BOOST_WAVE_THROW_CTX(ctx, cls, code, msg, act_pos) \
66 { \
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())); \
76 } \
77 /**/
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
85 #include <strstream>
86 #define BOOST_WAVE_THROW_NAME_CTX(ctx, cls, code, msg, act_pos, name) \
87 { \
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))); \
98 } \
99 /**/
100 #else
101 #include <sstream>
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))); \
114 /**/
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
122 #include <strstream>
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())); \
136 /**/
137 #else
138 #include <sstream>
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())); \
151 /**/
152 #endif // BOOST_NO_STRINGSTREAM
153 #endif // BOOST_WAVE_THROW_VAR
155 #endif // !defined(BOOST_WAVE_CPP_THROW_HPP_INCLUDED)