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 BOOST_EXCEPTION_274DA366004E11DCB1DDFE2E56D89593
7 #define BOOST_EXCEPTION_274DA366004E11DCB1DDFE2E56D89593
9 #include <boost/assert/source_location.hpp>
10 #include <boost/config.hpp>
13 #ifdef BOOST_EXCEPTION_MINI_BOOST
15 namespace boost { namespace exception_detail { using std::shared_ptr; } }
17 namespace boost { template <class T> class shared_ptr; }
18 namespace boost { namespace exception_detail { using boost::shared_ptr; } }
21 #if !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
22 #if __GNUC__*100+__GNUC_MINOR__>301
23 #pragma GCC system_header
26 #pragma clang system_header
29 #pragma warning(push,1)
30 #pragma warning(disable: 4265)
56 refcount_ptr( refcount_ptr const & x ):
63 operator=( refcount_ptr const & x )
97 if( px_ && px_->release() )
103 ////////////////////////////////////////////////////////////////////////
105 template <class Tag,class T>
108 typedef error_info<struct throw_function_,char const *> throw_function;
109 typedef error_info<struct throw_file_,char const *> throw_file;
110 typedef error_info<struct throw_line_,int> throw_line;
111 typedef error_info<struct throw_column_,int> throw_column;
115 error_info<throw_function_,char const *>
118 typedef char const * value_type;
121 error_info( value_type v ):
129 error_info<throw_file_,char const *>
132 typedef char const * value_type;
135 error_info( value_type v ):
143 error_info<throw_line_,int>
146 typedef int value_type;
149 error_info( value_type v ):
157 error_info<throw_column_,int>
160 typedef int value_type;
163 error_info( value_type v ):
176 class error_info_base;
182 virtual char const * diagnostic_information( char const * ) const = 0;
183 virtual shared_ptr<error_info_base> get( type_info_ const & ) const = 0;
184 virtual void set( shared_ptr<error_info_base> const &, type_info_ const & ) = 0;
185 virtual void add_ref() const = 0;
186 virtual bool release() const = 0;
187 virtual refcount_ptr<exception_detail::error_info_container> clone() const = 0;
191 ~error_info_container() BOOST_NOEXCEPT_OR_NOTHROW
200 struct get_info<throw_function>;
203 struct get_info<throw_file>;
206 struct get_info<throw_line>;
209 struct get_info<throw_column>;
215 struct set_info_rv<throw_function>;
218 struct set_info_rv<throw_file>;
221 struct set_info_rv<throw_line>;
224 struct set_info_rv<throw_column>;
226 char const * get_diagnostic_information( exception const &, char const * );
228 void copy_boost_exception( exception *, exception const * );
230 template <class E,class Tag,class T>
231 E const & set_info( E const &, error_info<Tag,T> const & );
234 E const & set_info( E const &, throw_function const & );
237 E const & set_info( E const &, throw_file const & );
240 E const & set_info( E const &, throw_line const & );
243 E const & set_info( E const &, throw_column const & );
245 boost::source_location get_exception_throw_location( exception const & );
254 template <class Tag> void set( typename Tag::type const & );
255 template <class Tag> typename Tag::type const * get() const;
269 //On HP aCC, this protected copy constructor prevents throwing boost::exception.
270 //On all other platforms, the same effect is achieved by the pure virtual destructor.
271 exception( exception const & x ) BOOST_NOEXCEPT_OR_NOTHROW:
273 throw_function_(x.throw_function_),
274 throw_file_(x.throw_file_),
275 throw_line_(x.throw_line_),
276 throw_column_(x.throw_column_)
281 virtual ~exception() BOOST_NOEXCEPT_OR_NOTHROW
283 = 0 //Workaround for HP aCC, =0 incorrectly leads to link errors.
287 #if (defined(__MWERKS__) && __MWERKS__<=0x3207) || (defined(_MSC_VER) && _MSC_VER<=1310)
293 friend E const & exception_detail::set_info( E const &, throw_function const & );
296 friend E const & exception_detail::set_info( E const &, throw_file const & );
299 friend E const & exception_detail::set_info( E const &, throw_line const & );
302 friend E const & exception_detail::set_info( E const &, throw_column const & );
304 template <class E,class Tag,class T>
305 friend E const & exception_detail::set_info( E const &, error_info<Tag,T> const & );
307 friend char const * exception_detail::get_diagnostic_information( exception const &, char const * );
309 friend boost::source_location exception_detail::get_exception_throw_location( exception const & );
312 friend struct exception_detail::get_info;
313 friend struct exception_detail::get_info<throw_function>;
314 friend struct exception_detail::get_info<throw_file>;
315 friend struct exception_detail::get_info<throw_line>;
316 friend struct exception_detail::get_info<throw_column>;
318 friend struct exception_detail::set_info_rv;
319 friend struct exception_detail::set_info_rv<throw_function>;
320 friend struct exception_detail::set_info_rv<throw_file>;
321 friend struct exception_detail::set_info_rv<throw_line>;
322 friend struct exception_detail::set_info_rv<throw_column>;
323 friend void exception_detail::copy_boost_exception( exception *, exception const * );
325 mutable exception_detail::refcount_ptr<exception_detail::error_info_container> data_;
326 mutable char const * throw_function_;
327 mutable char const * throw_file_;
328 mutable int throw_line_;
329 mutable int throw_column_;
334 ~exception() BOOST_NOEXCEPT_OR_NOTHROW
343 set_info( E const & x, throw_function const & y )
345 x.throw_function_=y.v_;
351 set_info( E const & x, throw_file const & y )
359 set_info( E const & x, throw_line const & y )
367 set_info( E const & x, throw_column const & y )
369 x.throw_column_=y.v_;
373 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
377 set_info_rv<throw_column>
382 set( E const & x, throw_column && y )
384 x.throw_column_=y.v_;
391 inline boost::source_location get_exception_throw_location( exception const & x )
393 return boost::source_location(
394 x.throw_file_? x.throw_file_: "",
395 x.throw_line_ >= 0? x.throw_line_: 0,
396 x.throw_function_? x.throw_function_: "",
397 x.throw_column_ >= 0? x.throw_column_: 0
402 ////////////////////////////////////////////////////////////////////////
415 error_info_injector( T const & x ):
420 ~error_info_injector() BOOST_NOEXCEPT_OR_NOTHROW
425 struct large_size { char c[256]; };
426 large_size dispatch_boost_exception( exception const * );
428 struct small_size { };
429 small_size dispatch_boost_exception( void const * );
432 struct enable_error_info_helper;
436 enable_error_info_helper<T,sizeof(large_size)>
443 enable_error_info_helper<T,sizeof(small_size)>
445 typedef error_info_injector<T> type;
450 enable_error_info_return_type
452 typedef typename enable_error_info_helper<T,sizeof(exception_detail::dispatch_boost_exception(static_cast<T *>(0)))>::type type;
459 exception_detail::enable_error_info_return_type<T>::type
460 enable_error_info( T const & x )
462 typedef typename exception_detail::enable_error_info_return_type<T>::type rt;
466 ////////////////////////////////////////////////////////////////////////
467 #if defined(BOOST_NO_EXCEPTIONS)
468 BOOST_NORETURN void throw_exception(std::exception const & e); // user defined
480 virtual clone_base const * clone() const = 0;
481 virtual void rethrow() const = 0;
484 ~clone_base() BOOST_NOEXCEPT_OR_NOTHROW
491 copy_boost_exception( exception * a, exception const * b )
493 refcount_ptr<error_info_container> data;
494 if( error_info_container * d=b->data_.get() )
496 a->throw_file_ = b->throw_file_;
497 a->throw_line_ = b->throw_line_;
498 a->throw_function_ = b->throw_function_;
499 a->throw_column_ = b->throw_column_;
505 copy_boost_exception( void *, void const * )
514 public virtual clone_base
516 struct clone_tag { };
517 clone_impl( clone_impl const & x, clone_tag ):
520 copy_boost_exception(this,&x);
526 clone_impl( T const & x ):
529 copy_boost_exception(this,&x);
532 ~clone_impl() BOOST_NOEXCEPT_OR_NOTHROW
541 return new clone_impl(*this,clone_tag());
547 #if defined(BOOST_NO_EXCEPTIONS)
548 boost::throw_exception(*this);
558 exception_detail::clone_impl<T>
559 enable_current_exception( T const & x )
561 return exception_detail::clone_impl<T>(x);
565 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
569 #endif // #ifndef BOOST_EXCEPTION_274DA366004E11DCB1DDFE2E56D89593