exception.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // -*- C++ -*-
  2. // Copyright (C) 2005-2018 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the terms
  6. // of the GNU General Public License as published by the Free Software
  7. // Foundation; either version 3, or (at your option) any later
  8. // version.
  9. // This library is distributed in the hope that it will be useful, but
  10. // WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. // General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
  21. // Permission to use, copy, modify, sell, and distribute this software
  22. // is hereby granted without fee, provided that the above copyright
  23. // notice appears in all copies, and that both that copyright notice
  24. // and this permission notice appear in supporting documentation. None
  25. // of the above authors, nor IBM Haifa Research Laboratories, make any
  26. // representation about the suitability of this software for any
  27. // purpose. It is provided "as is" without express or implied
  28. // warranty.
  29. /**
  30. * @file exception.hpp
  31. * Contains exception classes.
  32. */
  33. #ifndef PB_DS_EXCEPTION_HPP
  34. #define PB_DS_EXCEPTION_HPP
  35. #include <bits/c++config.h>
  36. #include <stdexcept>
  37. #include <cstdlib>
  38. namespace __gnu_pbds
  39. {
  40. /**
  41. * @defgroup exceptions-pbds Exceptions
  42. * @ingroup pbds
  43. * @{
  44. */
  45. /// Base class for exceptions.
  46. struct container_error : public std::logic_error
  47. {
  48. container_error()
  49. : std::logic_error(__N("__gnu_pbds::container_error")) { }
  50. };
  51. /// An entry cannot be inserted into a container object for logical
  52. /// reasons (not, e.g., if memory is unabvailable, in which case
  53. /// the allocator_type's exception will be thrown).
  54. struct insert_error : public container_error { };
  55. /// A join cannot be performed logical reasons (i.e., the ranges of
  56. /// the two container objects being joined overlaps.
  57. struct join_error : public container_error { };
  58. /// A container cannot be resized.
  59. struct resize_error : public container_error { };
  60. inline void
  61. __throw_container_error()
  62. { _GLIBCXX_THROW_OR_ABORT(container_error()); }
  63. inline void
  64. __throw_insert_error()
  65. { _GLIBCXX_THROW_OR_ABORT(insert_error()); }
  66. inline void
  67. __throw_join_error()
  68. { _GLIBCXX_THROW_OR_ABORT(join_error()); }
  69. inline void
  70. __throw_resize_error()
  71. { _GLIBCXX_THROW_OR_ABORT(resize_error()); }
  72. //@}
  73. } // namespace __gnu_pbds
  74. #endif