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
9 #include <boost/config.hpp>
11 #ifdef BOOST_EXCEPTION_MINI_BOOST
13 namespace boost { namespace exception_detail { using std::shared_ptr; } }
15 namespace boost { template <class T> class shared_ptr; }
16 namespace boost { namespace exception_detail { using boost::shared_ptr; } }
19 #if defined(__GNUC__) && (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
20 #pragma GCC system_header
22 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
23 #pragma warning(push,1)
24 #pragma warning(disable: 4265)
49 refcount_ptr( refcount_ptr const & x ):
56 operator=( refcount_ptr const & x )
90 if( px_ && px_->release() )
96 ////////////////////////////////////////////////////////////////////////
98 template <class Tag,class T>
101 typedef error_info<struct throw_function_,char const *> throw_function;
102 typedef error_info<struct throw_file_,char const *> throw_file;
103 typedef error_info<struct throw_line_,int> throw_line;
107 error_info<throw_function_,char const *>
110 typedef char const * value_type;
113 error_info( value_type v ):
121 error_info<throw_file_,char const *>
124 typedef char const * value_type;
127 error_info( value_type v ):
135 error_info<throw_line_,int>
138 typedef int value_type;
141 error_info( value_type v ):
154 class error_info_base;
160 virtual char const * diagnostic_information( char const * ) const = 0;
161 virtual shared_ptr<error_info_base> get( type_info_ const & ) const = 0;
162 virtual void set( shared_ptr<error_info_base> const &, type_info_ const & ) = 0;
163 virtual void add_ref() const = 0;
164 virtual bool release() const = 0;
165 virtual refcount_ptr<exception_detail::error_info_container> clone() const = 0;
169 ~error_info_container() BOOST_NOEXCEPT_OR_NOTHROW
178 struct get_info<throw_function>;
181 struct get_info<throw_file>;
184 struct get_info<throw_line>;
190 struct set_info_rv<throw_function>;
193 struct set_info_rv<throw_file>;
196 struct set_info_rv<throw_line>;
198 char const * get_diagnostic_information( exception const &, char const * );
200 void copy_boost_exception( exception *, exception const * );
202 template <class E,class Tag,class T>
203 E const & set_info( E const &, error_info<Tag,T> const & );
206 E const & set_info( E const &, throw_function const & );
209 E const & set_info( E const &, throw_file const & );
212 E const & set_info( E const &, throw_line const & );
221 template <class Tag> void set( typename Tag::type const & );
222 template <class Tag> typename Tag::type const * get() const;
235 //On HP aCC, this protected copy constructor prevents throwing boost::exception.
236 //On all other platforms, the same effect is achieved by the pure virtual destructor.
237 exception( exception const & x ) BOOST_NOEXCEPT_OR_NOTHROW:
239 throw_function_(x.throw_function_),
240 throw_file_(x.throw_file_),
241 throw_line_(x.throw_line_)
246 virtual ~exception() BOOST_NOEXCEPT_OR_NOTHROW
248 = 0 //Workaround for HP aCC, =0 incorrectly leads to link errors.
252 #if (defined(__MWERKS__) && __MWERKS__<=0x3207) || (defined(_MSC_VER) && _MSC_VER<=1310)
258 friend E const & exception_detail::set_info( E const &, throw_function const & );
261 friend E const & exception_detail::set_info( E const &, throw_file const & );
264 friend E const & exception_detail::set_info( E const &, throw_line const & );
266 template <class E,class Tag,class T>
267 friend E const & exception_detail::set_info( E const &, error_info<Tag,T> const & );
269 friend char const * exception_detail::get_diagnostic_information( exception const &, char const * );
272 friend struct exception_detail::get_info;
273 friend struct exception_detail::get_info<throw_function>;
274 friend struct exception_detail::get_info<throw_file>;
275 friend struct exception_detail::get_info<throw_line>;
277 friend struct exception_detail::set_info_rv;
278 friend struct exception_detail::set_info_rv<throw_function>;
279 friend struct exception_detail::set_info_rv<throw_file>;
280 friend struct exception_detail::set_info_rv<throw_line>;
281 friend void exception_detail::copy_boost_exception( exception *, exception const * );
283 mutable exception_detail::refcount_ptr<exception_detail::error_info_container> data_;
284 mutable char const * throw_function_;
285 mutable char const * throw_file_;
286 mutable int throw_line_;
291 ~exception() BOOST_NOEXCEPT_OR_NOTHROW
300 set_info( E const & x, throw_function const & y )
302 x.throw_function_=y.v_;
308 set_info( E const & x, throw_file const & y )
316 set_info( E const & x, throw_line const & y )
323 ////////////////////////////////////////////////////////////////////////
336 error_info_injector( T const & x ):
341 ~error_info_injector() BOOST_NOEXCEPT_OR_NOTHROW
346 struct large_size { char c[256]; };
347 large_size dispatch_boost_exception( exception const * );
349 struct small_size { };
350 small_size dispatch_boost_exception( void const * );
353 struct enable_error_info_helper;
357 enable_error_info_helper<T,sizeof(large_size)>
364 enable_error_info_helper<T,sizeof(small_size)>
366 typedef error_info_injector<T> type;
371 enable_error_info_return_type
373 typedef typename enable_error_info_helper<T,sizeof(exception_detail::dispatch_boost_exception(static_cast<T *>(0)))>::type type;
380 exception_detail::enable_error_info_return_type<T>::type
381 enable_error_info( T const & x )
383 typedef typename exception_detail::enable_error_info_return_type<T>::type rt;
387 ////////////////////////////////////////////////////////////////////////
398 virtual clone_base const * clone() const = 0;
399 virtual void rethrow() const = 0;
402 ~clone_base() BOOST_NOEXCEPT_OR_NOTHROW
409 copy_boost_exception( exception * a, exception const * b )
411 refcount_ptr<error_info_container> data;
412 if( error_info_container * d=b->data_.get() )
414 a->throw_file_ = b->throw_file_;
415 a->throw_line_ = b->throw_line_;
416 a->throw_function_ = b->throw_function_;
422 copy_boost_exception( void *, void const * )
431 public virtual clone_base
433 struct clone_tag { };
434 clone_impl( clone_impl const & x, clone_tag ):
437 copy_boost_exception(this,&x);
443 clone_impl( T const & x ):
446 copy_boost_exception(this,&x);
449 ~clone_impl() BOOST_NOEXCEPT_OR_NOTHROW
458 return new clone_impl(*this,clone_tag());
471 exception_detail::clone_impl<T>
472 enable_current_exception( T const & x )
474 return exception_detail::clone_impl<T>(x);
481 public exception_detail::clone_impl<typename exception_detail::enable_error_info_return_type<T>::type>
483 typedef exception_detail::clone_impl<typename exception_detail::enable_error_info_return_type<T>::type> base_type;
486 wrapexcept( typename exception_detail::enable_error_info_return_type<T>::type const & x ):
491 ~wrapexcept() BOOST_NOEXCEPT_OR_NOTHROW
501 remove_error_info_injector
508 remove_error_info_injector< error_info_injector<T> >
515 wrapexcept<typename remove_error_info_injector<T>::type>
516 enable_both( T const & x )
518 return wrapexcept<typename remove_error_info_injector<T>::type>( enable_error_info( x ) );
523 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)