bumping version to 3.5-rc1
[supercollider.git] / external_libraries / pycxx-6.2.2 / CXX / Python3 / Exception.hxx
blob0bd052d5cc7df0a686364b84f1a730a9eb9ea900
1 //-----------------------------------------------------------------------------
2 //
3 // Copyright (c) 1998 - 2007, The Regents of the University of California
4 // Produced at the Lawrence Livermore National Laboratory
5 // All rights reserved.
6 //
7 // This file is part of PyCXX. For details,see http://cxx.sourceforge.net/. The
8 // full copyright notice is contained in the file COPYRIGHT located at the root
9 // of the PyCXX distribution.
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are met:
14 // - Redistributions of source code must retain the above copyright notice,
15 // this list of conditions and the disclaimer below.
16 // - Redistributions in binary form must reproduce the above copyright notice,
17 // this list of conditions and the disclaimer (as noted below) in the
18 // documentation and/or materials provided with the distribution.
19 // - Neither the name of the UC/LLNL nor the names of its contributors may be
20 // used to endorse or promote products derived from this software without
21 // specific prior written permission.
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 // ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF
27 // CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR
28 // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
34 // DAMAGE.
36 //-----------------------------------------------------------------------------
38 #ifndef __CXX_Exception_h
39 #define __CXX_Exception_h
41 #include "CXX/WrapPython.h"
42 #include "CXX/Version.hxx"
43 #include "CXX/Python3/Config.hxx"
44 #include "CXX/Python3/CxxDebug.hxx"
45 #include "CXX/Python3/IndirectPythonInterface.hxx"
47 #include <string>
48 #include <iostream>
50 // This mimics the Python structure, in order to minimize confusion
51 namespace Py
53 class ExtensionExceptionType;
55 class Object;
57 class Exception
59 public:
60 Exception( ExtensionExceptionType &exception, const std::string &reason );
61 Exception( ExtensionExceptionType &exception, Object &reason );
63 explicit Exception ()
66 Exception (const std::string &reason)
68 PyErr_SetString( Py::_Exc_RuntimeError(), reason.c_str() );
71 Exception( PyObject *exception, const std::string &reason )
73 PyErr_SetString( exception, reason.c_str() );
76 Exception( PyObject *exception, Object &reason );
78 void clear() // clear the error
79 // technically but not philosophically const
81 PyErr_Clear();
86 // Abstract
87 class StandardError: public Exception
89 protected:
90 explicit StandardError()
94 class LookupError: public StandardError
96 protected:
97 explicit LookupError()
101 class ArithmeticError: public StandardError
103 protected:
104 explicit ArithmeticError()
108 class EnvironmentError: public StandardError
110 protected:
111 explicit EnvironmentError()
115 // Concrete
117 class TypeError: public StandardError
119 public:
120 TypeError (const std::string& reason)
121 : StandardError()
123 PyErr_SetString( Py::_Exc_TypeError(),reason.c_str() );
127 class IndexError: public LookupError
129 public:
130 IndexError (const std::string& reason)
131 : LookupError()
133 PyErr_SetString( Py::_Exc_IndexError(), reason.c_str() );
137 class AttributeError: public StandardError
139 public:
140 AttributeError (const std::string& reason)
141 : StandardError()
143 PyErr_SetString( Py::_Exc_AttributeError(), reason.c_str() );
147 class NameError: public StandardError
149 public:
150 NameError (const std::string& reason)
151 : StandardError()
153 PyErr_SetString( Py::_Exc_NameError(), reason.c_str() );
157 class RuntimeError: public StandardError
159 public:
160 RuntimeError (const std::string& reason)
161 : StandardError()
163 PyErr_SetString( Py::_Exc_RuntimeError(), reason.c_str() );
167 class NotImplementedError: public StandardError
169 public:
170 NotImplementedError (const std::string& reason)
171 : StandardError()
173 PyErr_SetString (Py::_Exc_NotImplementedError(), reason.c_str());
177 class SystemError: public StandardError
179 public:
180 SystemError (const std::string& reason)
181 : StandardError()
183 PyErr_SetString( Py::_Exc_SystemError(),reason.c_str() );
187 class KeyError: public LookupError
189 public:
190 KeyError (const std::string& reason)
191 : LookupError()
193 PyErr_SetString( Py::_Exc_KeyError(),reason.c_str() );
198 class ValueError: public StandardError
200 public:
201 ValueError (const std::string& reason)
202 : StandardError()
204 PyErr_SetString( Py::_Exc_ValueError(), reason.c_str() );
208 class OverflowError: public ArithmeticError
210 public:
211 OverflowError (const std::string& reason)
212 : ArithmeticError()
214 PyErr_SetString( Py::_Exc_OverflowError(), reason.c_str() );
218 class ZeroDivisionError: public ArithmeticError
220 public:
221 ZeroDivisionError (const std::string& reason)
222 : ArithmeticError()
224 PyErr_SetString( Py::_Exc_ZeroDivisionError(), reason.c_str() );
228 class FloatingPointError: public ArithmeticError
230 public:
231 FloatingPointError (const std::string& reason)
232 : ArithmeticError()
234 PyErr_SetString( Py::_Exc_FloatingPointError(), reason.c_str() );
238 class MemoryError: public StandardError
240 public:
241 MemoryError (const std::string& reason)
242 : StandardError()
244 PyErr_SetString( Py::_Exc_MemoryError(), reason.c_str() );
248 class SystemExit: public StandardError
250 public:
251 SystemExit (const std::string& reason)
252 : StandardError()
254 PyErr_SetString( Py::_Exc_SystemExit(),reason.c_str() );
258 }// Py
260 #endif