throw_exception.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef BHO_THROW_EXCEPTION_HPP_INCLUDED
  2. #define BHO_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. // bho/throw_exception.hpp
  8. //
  9. // Copyright (c) 2002, 2018-2022 Peter Dimov
  10. // Copyright (c) 2008-2009 Emil Dotchevski and Reverge Studios, Inc.
  11. //
  12. // Distributed under the Boost Software License, Version 1.0. (See
  13. // accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt)
  15. //
  16. // http://www.boost.org/libs/throw_exception
  17. #include <asio2/bho/assert/source_location.hpp>
  18. #include <asio2/bho/config.hpp>
  19. #include <asio2/bho/config/workaround.hpp>
  20. #include <exception>
  21. #include <utility>
  22. #include <cstddef>
  23. #if !defined(BHO_NO_CXX11_HDR_TYPE_TRAITS)
  24. #include <type_traits>
  25. #endif
  26. #if !defined( BHO_EXCEPTION_DISABLE ) && defined( BHO_BORLANDC ) && BHO_WORKAROUND( BHO_BORLANDC, BHO_TESTED_AT(0x593) )
  27. # define BHO_EXCEPTION_DISABLE
  28. #endif
  29. namespace bho
  30. {
  31. #if defined( BHO_NO_EXCEPTIONS )
  32. BHO_NORETURN void throw_exception( std::exception const & e ); // user defined
  33. BHO_NORETURN void throw_exception( std::exception const & e, bho::source_location const & loc ); // user defined
  34. #endif
  35. // All boost exceptions are required to derive from std::exception,
  36. // to ensure compatibility with BHO_NO_EXCEPTIONS.
  37. inline void throw_exception_assert_compatibility( std::exception const & ) {}
  38. // bho::throw_exception
  39. #if !defined( BHO_NO_EXCEPTIONS )
  40. #if defined( BHO_EXCEPTION_DISABLE )
  41. template<class E> BHO_NORETURN void throw_exception( E const & e )
  42. {
  43. throw_exception_assert_compatibility( e );
  44. throw e;
  45. }
  46. template<class E> BHO_NORETURN void throw_exception( E const & e, bho::source_location const & )
  47. {
  48. throw_exception_assert_compatibility( e );
  49. throw e;
  50. }
  51. #else // defined( BHO_EXCEPTION_DISABLE )
  52. template<class E> BHO_NORETURN void throw_exception( E const & e )
  53. {
  54. throw_exception_assert_compatibility( e );
  55. throw e;
  56. }
  57. template<class E> BHO_NORETURN void throw_exception( E const & e, bho::source_location const & loc )
  58. {
  59. throw_exception_assert_compatibility( e );
  60. ((void)loc); throw e;
  61. }
  62. #endif // defined( BHO_EXCEPTION_DISABLE )
  63. #endif // !defined( BHO_NO_EXCEPTIONS )
  64. } // namespace bho
  65. // BHO_THROW_EXCEPTION
  66. #define BHO_THROW_EXCEPTION(x) ::bho::throw_exception(x, BHO_CURRENT_LOCATION)
  67. #endif // #ifndef BHO_THROW_EXCEPTION_HPP_INCLUDED