throw_exception.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2012-2013. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_CONTAINER_THROW_EXCEPTION_HPP
  11. #define BOOST_CONTAINER_THROW_EXCEPTION_HPP
  12. #include <boost/container/detail/config_begin.hpp>
  13. #include <boost/container/detail/workaround.hpp>
  14. #if defined(_MSC_VER)
  15. # pragma once
  16. #endif
  17. #ifndef BOOST_NO_EXCEPTIONS
  18. #include <stdexcept> //for std exception types
  19. #include <new> //for std::bad_alloc
  20. #else
  21. #include <boost/assert.hpp>
  22. #include <cstdlib> //for std::abort
  23. #endif
  24. namespace boost {
  25. namespace container {
  26. #if defined(BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS)
  27. //The user must provide definitions for the following functions
  28. void throw_bad_alloc();
  29. void throw_out_of_range(const char* str);
  30. void throw_length_error(const char* str);
  31. void throw_logic_error(const char* str);
  32. void throw_runtime_error(const char* str);
  33. #elif defined(BOOST_NO_EXCEPTIONS)
  34. inline void throw_bad_alloc()
  35. {
  36. BOOST_ASSERT(!"boost::container bad_alloc thrown");
  37. std::abort();
  38. }
  39. inline void throw_out_of_range(const char* str)
  40. {
  41. BOOST_ASSERT_MSG(!"boost::container out_of_range thrown", str);
  42. std::abort();
  43. }
  44. inline void throw_length_error(const char* str)
  45. {
  46. BOOST_ASSERT_MSG(!"boost::container length_error thrown", str);
  47. std::abort();
  48. }
  49. inline void throw_logic_error(const char* str)
  50. {
  51. BOOST_ASSERT_MSG(!"boost::container logic_error thrown", str);
  52. std::abort();
  53. }
  54. inline void throw_runtime_error(const char* str)
  55. {
  56. BOOST_ASSERT_MSG(!"boost::container runtime_error thrown", str);
  57. std::abort();
  58. }
  59. #else //defined(BOOST_NO_EXCEPTIONS)
  60. inline void throw_bad_alloc()
  61. {
  62. throw std::bad_alloc();
  63. }
  64. inline void throw_out_of_range(const char* str)
  65. {
  66. throw std::out_of_range(str);
  67. }
  68. inline void throw_length_error(const char* str)
  69. {
  70. throw std::length_error(str);
  71. }
  72. inline void throw_logic_error(const char* str)
  73. {
  74. throw std::logic_error(str);
  75. }
  76. inline void throw_runtime_error(const char* str)
  77. {
  78. throw std::runtime_error(str);
  79. }
  80. #endif
  81. }} //namespace boost { namespace container {
  82. #include <boost/container/detail/config_end.hpp>
  83. #endif //#ifndef BOOST_CONTAINER_THROW_EXCEPTION_HPP