throw_exception.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <boost/config.hpp>
  22. #include <exception>
  23. #if !defined( BOOST_EXCEPTION_DISABLE ) && defined( __BORLANDC__ ) && BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT(0x593) )
  24. # define BOOST_EXCEPTION_DISABLE
  25. #endif
  26. #if !defined( BOOST_EXCEPTION_DISABLE ) && defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, < 1310 )
  27. # define BOOST_EXCEPTION_DISABLE
  28. #endif
  29. #if !defined( BOOST_EXCEPTION_DISABLE )
  30. # include <boost/exception/exception.hpp>
  31. # include <boost/current_function.hpp>
  32. # define BOOST_THROW_EXCEPTION(x) ::boost::exception_detail::throw_exception_(x,BOOST_CURRENT_FUNCTION,__FILE__,__LINE__)
  33. #else
  34. # define BOOST_THROW_EXCEPTION(x) ::boost::throw_exception(x)
  35. #endif
  36. namespace boost
  37. {
  38. #ifdef BOOST_NO_EXCEPTIONS
  39. void throw_exception( std::exception const & e ); // user defined
  40. #else
  41. inline void throw_exception_assert_compatibility( std::exception const & ) { }
  42. template<class E> BOOST_ATTRIBUTE_NORETURN inline void throw_exception( E const & e )
  43. {
  44. //All boost exceptions are required to derive from std::exception,
  45. //to ensure compatibility with BOOST_NO_EXCEPTIONS.
  46. throw_exception_assert_compatibility(e);
  47. #ifndef BOOST_EXCEPTION_DISABLE
  48. throw enable_current_exception(enable_error_info(e));
  49. #else
  50. throw e;
  51. #endif
  52. }
  53. #endif
  54. #if !defined( BOOST_EXCEPTION_DISABLE )
  55. namespace
  56. exception_detail
  57. {
  58. template <class E>
  59. BOOST_ATTRIBUTE_NORETURN
  60. void
  61. throw_exception_( E const & x, char const * current_function, char const * file, int line )
  62. {
  63. boost::throw_exception(
  64. set_info(
  65. set_info(
  66. set_info(
  67. enable_error_info(x),
  68. throw_function(current_function)),
  69. throw_file(file)),
  70. throw_line(line)));
  71. }
  72. }
  73. #endif
  74. } // namespace boost
  75. #endif // #ifndef BOOST_THROW_EXCEPTION_HPP_INCLUDED