throw_exception.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /// Copyright (c) 2008-2021 Emil Dotchevski and Reverge Studios, Inc.
  2. /// Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. /// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #ifndef BOOST_QVM_THROW_EXCEPTION
  5. # define BOOST_QVM_THROW_EXCEPTION ::boost::qvm::throw_exception
  6. # include <exception>
  7. # ifndef BOOST_QVM_NO_EXCEPTIONS
  8. # if defined(__clang__) && !defined(__ibmxl__) // Clang C++ emulates GCC, so it has to appear early.
  9. # if !__has_feature(cxx_exceptions)
  10. # define BOOST_QVM_NO_EXCEPTIONS
  11. # endif
  12. # elif defined(__DMC__) // Digital Mars C++
  13. # if !defined(_CPPUNWIND)
  14. # define BOOST_QVM_NO_EXCEPTIONS
  15. # endif
  16. # elif defined(__GNUC__) && !defined(__ibmxl__) // GNU C++:
  17. # if !defined(__EXCEPTIONS)
  18. # define BOOST_QVM_NO_EXCEPTIONS
  19. # endif
  20. # elif defined(__KCC) // Kai C++
  21. # if !defined(_EXCEPTIONS)
  22. # define BOOST_QVM_NO_EXCEPTIONS
  23. # endif
  24. # elif defined(__CODEGEARC__) // CodeGear - must be checked for before Borland
  25. # if !defined(_CPPUNWIND) && !defined(__EXCEPTIONS)
  26. # define BOOST_QVM_NO_EXCEPTIONS
  27. # endif
  28. # elif defined(__BORLANDC__) // Borland
  29. # if !defined(_CPPUNWIND) && !defined(__EXCEPTIONS)
  30. # define BOOST_QVM_NO_EXCEPTIONS
  31. # endif
  32. # elif defined(__MWERKS__) // Metrowerks CodeWarrior
  33. # if !__option(exceptions)
  34. # define BOOST_QVM_NO_EXCEPTIONS
  35. # endif
  36. # elif defined(__IBMCPP__) && defined(__COMPILER_VER__) && defined(__MVS__) // IBM z/OS XL C/C++
  37. # if !defined(_CPPUNWIND) && !defined(__EXCEPTIONS)
  38. # define BOOST_QVM_NO_EXCEPTIONS
  39. # endif
  40. # elif defined(__ibmxl__) // IBM XL C/C++ for Linux (Little Endian)
  41. # if !__has_feature(cxx_exceptions)
  42. # define BOOST_QVM_NO_EXCEPTIONS
  43. # endif
  44. # elif defined(_MSC_VER) // Microsoft Visual C++
  45. // Must remain the last #elif since some other vendors (Metrowerks, for
  46. // example) also #define _MSC_VER
  47. # if !defined(_CPPUNWIND)
  48. # define BOOST_QVM_NO_EXCEPTIONS
  49. # endif
  50. # endif
  51. # endif
  52. ////////////////////////////////////////
  53. # ifdef BOOST_NORETURN
  54. # define BOOST_QVM_NORETURN BOOST_NORETURN
  55. # else
  56. # if defined(_MSC_VER)
  57. # define BOOST_QVM_NORETURN __declspec(noreturn)
  58. # elif defined(__GNUC__)
  59. # define BOOST_QVM_NORETURN __attribute__ ((__noreturn__))
  60. # elif defined(__has_attribute) && defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x5130)
  61. # if __has_attribute(noreturn)
  62. # define BOOST_QVM_NORETURN [[noreturn]]
  63. # endif
  64. # elif defined(__has_cpp_attribute)
  65. # if __has_cpp_attribute(noreturn)
  66. # define BOOST_QVM_NORETURN [[noreturn]]
  67. # endif
  68. # endif
  69. # endif
  70. # if !defined(BOOST_QVM_NORETURN)
  71. # define BOOST_QVM_NORETURN
  72. # endif
  73. ////////////////////////////////////////
  74. # ifdef BOOST_QVM_NO_EXCEPTIONS
  75. namespace boost
  76. {
  77. BOOST_QVM_NORETURN void throw_exception( std::exception const & ); // user defined
  78. }
  79. namespace boost { namespace qvm {
  80. template <class T>
  81. BOOST_QVM_NORETURN void throw_exception( T const & e )
  82. {
  83. ::boost::throw_exception(e);
  84. }
  85. } }
  86. # else
  87. namespace boost { namespace qvm {
  88. template <class T>
  89. BOOST_QVM_NORETURN void throw_exception( T const & e )
  90. {
  91. throw e;
  92. }
  93. } }
  94. # endif
  95. #endif