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