Python2/Exception.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef __CXX_Exception_h
00039 #define __CXX_Exception_h
00040
00041 #include "CXX/WrapPython.h"
00042 #include "CXX/Version.hxx"
00043 #include "CXX/Config.hxx"
00044 #include "CXX/IndirectPythonInterface.hxx"
00045
00046 #include <string>
00047 #include <iostream>
00048
00049
00050 namespace Py
00051 {
00052 class ExtensionExceptionType;
00053
00054 class Object;
00055
00056 class PYCXX_EXPORT Exception
00057 {
00058 public:
00059 Exception( ExtensionExceptionType &exception, const std::string& reason );
00060 Exception( ExtensionExceptionType &exception, Object &reason );
00061
00062 explicit Exception ()
00063 {}
00064
00065 Exception (const std::string& reason)
00066 {
00067 PyErr_SetString (Py::_Exc_RuntimeError(), reason.c_str());
00068 }
00069
00070 Exception (PyObject* exception, const std::string& reason)
00071 {
00072 PyErr_SetString (exception, reason.c_str());
00073 }
00074
00075 Exception (PyObject* exception, Object &reason);
00076
00077 void clear()
00078
00079 {
00080 PyErr_Clear();
00081 }
00082 };
00083
00084
00085
00086 class PYCXX_EXPORT StandardError: public Exception
00087 {
00088 protected:
00089 explicit StandardError()
00090 {}
00091 };
00092
00093 class PYCXX_EXPORT LookupError: public StandardError
00094 {
00095 protected:
00096 explicit LookupError()
00097 {}
00098 };
00099
00100 class PYCXX_EXPORT ArithmeticError: public StandardError
00101 {
00102 protected:
00103 explicit ArithmeticError()
00104 {}
00105 };
00106
00107 class PYCXX_EXPORT EnvironmentError: public StandardError
00108 {
00109 protected:
00110 explicit EnvironmentError()
00111 {}
00112 };
00113
00114
00115
00116 class PYCXX_EXPORT TypeError: public StandardError
00117 {
00118 public:
00119 TypeError (const std::string& reason)
00120 : StandardError()
00121 {
00122 PyErr_SetString (Py::_Exc_TypeError(),reason.c_str());
00123 }
00124 };
00125
00126 class PYCXX_EXPORT IndexError: public LookupError
00127 {
00128 public:
00129 IndexError (const std::string& reason)
00130 : LookupError()
00131 {
00132 PyErr_SetString (Py::_Exc_IndexError(), reason.c_str());
00133 }
00134 };
00135
00136 class PYCXX_EXPORT AttributeError: public StandardError
00137 {
00138 public:
00139 AttributeError (const std::string& reason)
00140 : StandardError()
00141 {
00142 PyErr_SetString (Py::_Exc_AttributeError(), reason.c_str());
00143 }
00144 };
00145
00146 class PYCXX_EXPORT NameError: public StandardError
00147 {
00148 public:
00149 NameError (const std::string& reason)
00150 : StandardError()
00151 {
00152 PyErr_SetString (Py::_Exc_NameError(), reason.c_str());
00153 }
00154 };
00155
00156 class PYCXX_EXPORT RuntimeError: public StandardError
00157 {
00158 public:
00159 RuntimeError (const std::string& reason)
00160 : StandardError()
00161 {
00162 PyErr_SetString (Py::_Exc_RuntimeError(), reason.c_str());
00163 }
00164 };
00165
00166 class PYCXX_EXPORT SystemError: public StandardError
00167 {
00168 public:
00169 SystemError (const std::string& reason)
00170 : StandardError()
00171 {
00172 PyErr_SetString (Py::_Exc_SystemError(),reason.c_str());
00173 }
00174 };
00175
00176 class PYCXX_EXPORT KeyError: public LookupError
00177 {
00178 public:
00179 KeyError (const std::string& reason)
00180 : LookupError()
00181 {
00182 PyErr_SetString (Py::_Exc_KeyError(),reason.c_str());
00183 }
00184 };
00185
00186
00187 class PYCXX_EXPORT ValueError: public StandardError
00188 {
00189 public:
00190 ValueError (const std::string& reason)
00191 : StandardError()
00192 {
00193 PyErr_SetString (Py::_Exc_ValueError(), reason.c_str());
00194 }
00195 };
00196
00197 class PYCXX_EXPORT OverflowError: public ArithmeticError
00198 {
00199 public:
00200 OverflowError (const std::string& reason)
00201 : ArithmeticError()
00202 {
00203 PyErr_SetString (Py::_Exc_OverflowError(), reason.c_str());
00204 }
00205 };
00206
00207 class PYCXX_EXPORT ZeroDivisionError: public ArithmeticError
00208 {
00209 public:
00210 ZeroDivisionError (const std::string& reason)
00211 : ArithmeticError()
00212 {
00213 PyErr_SetString (Py::_Exc_ZeroDivisionError(), reason.c_str());
00214 }
00215 };
00216
00217 class PYCXX_EXPORT FloatingPointError: public ArithmeticError
00218 {
00219 public:
00220 FloatingPointError (const std::string& reason)
00221 : ArithmeticError()
00222 {
00223 PyErr_SetString (Py::_Exc_FloatingPointError(), reason.c_str());
00224 }
00225 };
00226
00227 class PYCXX_EXPORT MemoryError: public StandardError
00228 {
00229 public:
00230 MemoryError (const std::string& reason)
00231 : StandardError()
00232 {
00233 PyErr_SetString (Py::_Exc_MemoryError(), reason.c_str());
00234 }
00235 };
00236
00237 class PYCXX_EXPORT SystemExit: public StandardError
00238 {
00239 public:
00240 SystemExit (const std::string& reason)
00241 : StandardError()
00242 {
00243 PyErr_SetString (Py::_Exc_SystemExit(),reason.c_str());
00244 }
00245 };
00246
00247 }
00248
00249 #endif