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