1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef UUID_274DA366004E11DCB1DDFE2E56D89593
7 #define UUID_274DA366004E11DCB1DDFE2E56D89593
8 #if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
9 #pragma GCC system_header
11 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
12 #pragma warning(push,1)
37 refcount_ptr( refcount_ptr const & x ):
44 operator=( refcount_ptr const & x )
84 ////////////////////////////////////////////////////////////////////////
86 template <class Tag,class T>
89 typedef error_info<struct throw_function_,char const *> throw_function;
90 typedef error_info<struct throw_file_,char const *> throw_file;
91 typedef error_info<struct throw_line_,int> throw_line;
95 error_info<throw_function_,char const *>
98 typedef char const * value_type;
101 error_info( value_type v ):
109 error_info<throw_file_,char const *>
112 typedef char const * value_type;
115 error_info( value_type v ):
123 error_info<throw_line_,int>
126 typedef int value_type;
129 error_info( value_type v ):
135 template <class E,class Tag,class T>
136 E const & operator<<( E const &, error_info<Tag,T> const & );
139 E const & operator<<( E const &, throw_function const & );
142 E const & operator<<( E const &, throw_file const & );
145 E const & operator<<( E const &, throw_line const & );
155 class error_info_base;
161 virtual char const * diagnostic_information( char const * ) const = 0;
162 virtual shared_ptr<error_info_base> get( type_info_ const & ) const = 0;
163 virtual void set( shared_ptr<error_info_base> const &, type_info_ const & ) = 0;
164 virtual void add_ref() const = 0;
165 virtual void release() const = 0;
169 ~error_info_container() throw()
178 struct get_info<throw_function>;
181 struct get_info<throw_file>;
184 struct get_info<throw_line>;
186 char const * get_diagnostic_information( exception const &, char const * );
202 //On HP aCC, this protected copy constructor prevents throwing boost::exception.
203 //On all other platforms, the same effect is achieved by the pure virtual destructor.
204 exception( exception const & x ) throw():
206 throw_function_(x.throw_function_),
207 throw_file_(x.throw_file_),
208 throw_line_(x.throw_line_)
213 virtual ~exception() throw()
215 = 0 //Workaround for HP aCC, =0 incorrectly leads to link errors.
219 #if defined(__MWERKS__) && __MWERKS__<=0x3207
225 friend E const & operator<<( E const &, throw_function const & );
228 friend E const & operator<<( E const &, throw_file const & );
231 friend E const & operator<<( E const &, throw_line const & );
233 friend char const * exception_detail::get_diagnostic_information( exception const &, char const * );
235 template <class E,class Tag,class T>
236 friend E const & operator<<( E const &, error_info<Tag,T> const & );
239 friend struct exception_detail::get_info;
240 friend struct exception_detail::get_info<throw_function>;
241 friend struct exception_detail::get_info<throw_file>;
242 friend struct exception_detail::get_info<throw_line>;
244 mutable exception_detail::refcount_ptr<exception_detail::error_info_container> data_;
245 mutable char const * throw_function_;
246 mutable char const * throw_file_;
247 mutable int throw_line_;
258 operator<<( E const & x, throw_function const & y )
260 x.throw_function_=y.v_;
266 operator<<( E const & x, throw_file const & y )
274 operator<<( E const & x, throw_line const & y )
280 ////////////////////////////////////////////////////////////////////////
292 error_info_injector( T const & x ):
297 ~error_info_injector() throw()
302 struct large_size { char c[256]; };
303 large_size dispatch( exception * );
305 struct small_size { };
306 small_size dispatch( void * );
309 struct enable_error_info_helper;
313 enable_error_info_helper<T,sizeof(large_size)>
320 enable_error_info_helper<T,sizeof(small_size)>
322 typedef error_info_injector<T> type;
327 enable_error_info_return_type
329 typedef typename enable_error_info_helper<T,sizeof(exception_detail::dispatch((T*)0))>::type type;
336 exception_detail::enable_error_info_return_type<T>::type
337 enable_error_info( T const & x )
339 typedef typename exception_detail::enable_error_info_return_type<T>::type rt;
343 ////////////////////////////////////////////////////////////////////////
353 virtual clone_base const * clone() const = 0;
354 virtual void rethrow() const = 0;
357 ~clone_base() throw()
364 copy_boost_exception( exception * a, exception const * b )
371 copy_boost_exception( void *, void const * )
384 clone_impl( T const & x ):
387 copy_boost_exception(this,&x);
390 ~clone_impl() throw()
399 return new clone_impl(*this);
412 exception_detail::clone_impl<T>
413 enable_current_exception( T const & x )
415 return exception_detail::clone_impl<T>(x);
419 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)