throw_exception.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef BOOST_THROW_EXCEPTION_HPP_INCLUDED
  2. #define BOOST_THROW_EXCEPTION_HPP_INCLUDED
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. //
  8. // boost/throw_exception.hpp
  9. //
  10. // Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
  11. // Copyright (c) 2008-2009 Emil Dotchevski and Reverge Studios, Inc.
  12. //
  13. // Distributed under the Boost Software License, Version 1.0. (See
  14. // accompanying file LICENSE_1_0.txt or copy at
  15. // http://www.boost.org/LICENSE_1_0.txt)
  16. //
  17. // http://www.boost.org/libs/utility/throw_exception.html
  18. //
  19. #include <boost/exception/detail/attribute_noreturn.hpp>
  20. #include <boost/detail/workaround.hpp>
  21. #include <exception>
  22. #if !defined( BOOST_EXCEPTION_DISABLE ) && defined( __BORLANDC__ ) && BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT(0x593) )
  23. # define BOOST_EXCEPTION_DISABLE
  24. #endif
  25. #if !defined( BOOST_EXCEPTION_DISABLE ) && defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, < 1310 )
  26. # define BOOST_EXCEPTION_DISABLE
  27. #endif
  28. #if !defined( BOOST_EXCEPTION_DISABLE )
  29. # include <boost/exception/exception.hpp>
  30. # include <boost/current_function.hpp>
  31. # define BOOST_THROW_EXCEPTION(x) ::boost::throw_exception(::boost::enable_error_info(x) <<\
  32. ::boost::throw_function(BOOST_CURRENT_FUNCTION) <<\
  33. ::boost::throw_file(__FILE__) <<\
  34. ::boost::throw_line((int)__LINE__))
  35. #else
  36. # define BOOST_THROW_EXCEPTION(x) ::boost::throw_exception(x)
  37. #endif
  38. namespace boost
  39. {
  40. #ifdef BOOST_NO_EXCEPTIONS
  41. void throw_exception( std::exception const & e ); // user defined
  42. #else
  43. inline void throw_exception_assert_compatibility( std::exception const & ) { }
  44. template<class E> BOOST_ATTRIBUTE_NORETURN inline void throw_exception( E const & e )
  45. {
  46. //All boost exceptions are required to derive std::exception,
  47. //to ensure compatibility with BOOST_NO_EXCEPTIONS.
  48. throw_exception_assert_compatibility(e);
  49. #ifndef BOOST_EXCEPTION_DISABLE
  50. throw enable_current_exception(enable_error_info(e));
  51. #else
  52. throw e;
  53. #endif
  54. }
  55. #endif
  56. } // namespace boost
  57. #endif // #ifndef BOOST_THROW_EXCEPTION_HPP_INCLUDED