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 )
78 if( px_ && px_->release() )
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 ):
143 class error_info_base;
149 virtual char const * diagnostic_information( char const * ) const = 0;
150 virtual shared_ptr<error_info_base> get( type_info_ const & ) const = 0;
151 virtual void set( shared_ptr<error_info_base> const &, type_info_ const & ) = 0;
152 virtual void add_ref() const = 0;
153 virtual bool release() const = 0;
154 virtual refcount_ptr<exception_detail::error_info_container> clone() const = 0;
158 ~error_info_container() throw()
167 struct get_info<throw_function>;
170 struct get_info<throw_file>;
173 struct get_info<throw_line>;
175 char const * get_diagnostic_information( exception const &, char const * );
177 void copy_boost_exception( exception *, exception const * );
179 template <class E,class Tag,class T>
180 E const & set_info( E const &, error_info<Tag,T> const & );
183 E const & set_info( E const &, throw_function const & );
186 E const & set_info( E const &, throw_file const & );
189 E const & set_info( E const &, throw_line const & );
205 //On HP aCC, this protected copy constructor prevents throwing boost::exception.
206 //On all other platforms, the same effect is achieved by the pure virtual destructor.
207 exception( exception const & x ) throw():
209 throw_function_(x.throw_function_),
210 throw_file_(x.throw_file_),
211 throw_line_(x.throw_line_)
216 virtual ~exception() throw()
218 = 0 //Workaround for HP aCC, =0 incorrectly leads to link errors.
222 #if (defined(__MWERKS__) && __MWERKS__<=0x3207) || (defined(_MSC_VER) && _MSC_VER<=1310)
228 friend E const & exception_detail::set_info( E const &, throw_function const & );
231 friend E const & exception_detail::set_info( E const &, throw_file const & );
234 friend E const & exception_detail::set_info( E const &, throw_line const & );
236 template <class E,class Tag,class T>
237 friend E const & exception_detail::set_info( E const &, error_info<Tag,T> const & );
239 friend char const * exception_detail::get_diagnostic_information( exception const &, char const * );
242 friend struct exception_detail::get_info;
243 friend struct exception_detail::get_info<throw_function>;
244 friend struct exception_detail::get_info<throw_file>;
245 friend struct exception_detail::get_info<throw_line>;
246 friend void exception_detail::copy_boost_exception( exception *, exception const * );
248 mutable exception_detail::refcount_ptr<exception_detail::error_info_container> data_;
249 mutable char const * throw_function_;
250 mutable char const * throw_file_;
251 mutable int throw_line_;
265 set_info( E const & x, throw_function const & y )
267 x.throw_function_=y.v_;
273 set_info( E const & x, throw_file const & y )
281 set_info( E const & x, throw_line const & y )
288 ////////////////////////////////////////////////////////////////////////
300 error_info_injector( T const & x ):
305 ~error_info_injector() throw()
310 struct large_size { char c[256]; };
311 large_size dispatch_boost_exception( exception const * );
313 struct small_size { };
314 small_size dispatch_boost_exception( void const * );
317 struct enable_error_info_helper;
321 enable_error_info_helper<T,sizeof(large_size)>
328 enable_error_info_helper<T,sizeof(small_size)>
330 typedef error_info_injector<T> type;
335 enable_error_info_return_type
337 typedef typename enable_error_info_helper<T,sizeof(exception_detail::dispatch_boost_exception((T*)0))>::type type;
344 exception_detail::enable_error_info_return_type<T>::type
345 enable_error_info( T const & x )
347 typedef typename exception_detail::enable_error_info_return_type<T>::type rt;
351 ////////////////////////////////////////////////////////////////////////
361 virtual clone_base const * clone() const = 0;
362 virtual void rethrow() const = 0;
365 ~clone_base() throw()
372 copy_boost_exception( exception * a, exception const * b )
374 refcount_ptr<error_info_container> data;
375 if( error_info_container * d=b->data_.get() )
377 a->throw_file_ = b->throw_file_;
378 a->throw_line_ = b->throw_line_;
379 a->throw_function_ = b->throw_function_;
385 copy_boost_exception( void *, void const * )
398 clone_impl( T const & x ):
401 copy_boost_exception(this,&x);
404 ~clone_impl() throw()
413 return new clone_impl(*this);
426 exception_detail::clone_impl<T>
427 enable_current_exception( T const & x )
429 return exception_detail::clone_impl<T>(x);
433 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)