1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
{- arch-tag: Python low-level exception definitions
Copyright (C) 2005 John Goerzen <jgoerzen@complete.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-}
{- |
Module : Python.Exceptions.ExcTypes
Copyright : Copyright (C) 2005 John Goerzen
License : GNU GPL, version 2 or above
Maintainer : John Goerzen,
Maintainer : jgoerzen@complete.org
Stability : provisional
Portability: portable
Python low-level exception definitions
These are definitions of the built-in Python exception objects. You can
use them with 'MissingPy.Python.Exceptions.doesExceptionMatch' and
'MissingPy.Python.Exceptions.catchSpecificPy'.
The meanings of these exceptions can be found at
<http://www.python.org/doc/current/lib/module-exceptions.html>.
Please note that windowsError is available only on Microsoft platforms.
Written by John Goerzen, jgoerzen\@complete.org
-}
module Python.Exceptions.ExcTypes
(pyMainException,
standardError, arithmeticError, lookupError, assertionError, attributeError,
pyEOFError, environmentError, floatingPointError, pyIOError, importError,
indexError, keyError, keyboardInterrupt, memoryError, nameError,
notImplementedError, pyOSError, overflowError, referenceError, runtimeError,
syntaxError, systemError, systemExit, typeError, valueError,
#ifdef MS_WINDOWS
windowsError,
#endif
zeroDivisionError)
where
import Python.Types
import Python.Objects
import System.IO.Unsafe
import Python.Utils
import Foreign
#include <Python.h>
-- e :: Ptr (Ptr CPyObject) -> PyObject
exctypes_internal_e x = unsafePerformIO $ do p <- peek x
fp <- newForeignPtr_ p
return $ PyObject fp
-- | Exception in Python
pyMainException :: PyObject
pyMainException = exctypes_internal_e cException
standardError :: PyObject
standardError = exctypes_internal_e cStandardError
arithmeticError :: PyObject
arithmeticError = exctypes_internal_e cArithmeticError
lookupError :: PyObject
lookupError = exctypes_internal_e cLookupError
assertionError :: PyObject
assertionError = exctypes_internal_e cAssertionError
attributeError :: PyObject
attributeError = exctypes_internal_e cAttributeError
pyEOFError :: PyObject
pyEOFError = exctypes_internal_e cEOFError
environmentError :: PyObject
environmentError = exctypes_internal_e cEnvironmentError
floatingPointError :: PyObject
floatingPointError = exctypes_internal_e cFloatingPointError
pyIOError :: PyObject
pyIOError = exctypes_internal_e cStandardError
importError :: PyObject
importError = exctypes_internal_e cImportError
indexError :: PyObject
indexError = exctypes_internal_e cIndexError
keyError :: PyObject
keyError = exctypes_internal_e cKeyError
keyboardInterrupt :: PyObject
keyboardInterrupt = exctypes_internal_e cKeyboardInterrupt
memoryError :: PyObject
memoryError = exctypes_internal_e cMemoryError
nameError :: PyObject
nameError = exctypes_internal_e cNameError
notImplementedError :: PyObject
notImplementedError = exctypes_internal_e cNotImplementedError
pyOSError :: PyObject
pyOSError = exctypes_internal_e cOSError
overflowError :: PyObject
overflowError = exctypes_internal_e cOverflowError
referenceError :: PyObject
referenceError = exctypes_internal_e cReferenceError
runtimeError :: PyObject
runtimeError = exctypes_internal_e cRuntimeError
syntaxError :: PyObject
syntaxError = exctypes_internal_e cSyntaxError
systemError :: PyObject
systemError = exctypes_internal_e cSystemError
systemExit :: PyObject
systemExit = exctypes_internal_e cSystemExit
typeError :: PyObject
typeError = exctypes_internal_e cTypeError
valueError :: PyObject
valueError = exctypes_internal_e cValueError
#ifdef MS_WINDOWS
windowsError :: PyObject
windowsError = exctypes_internal_e cWindowsError
#endif
zeroDivisionError :: PyObject
zeroDivisionError = exctypes_internal_e cZeroDivisionError
foreign import ccall unsafe "&PyExc_Exception" cException :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_StandardError" cStandardError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_ArithmeticError" cArithmeticError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_LookupError" cLookupError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_AssertionError" cAssertionError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_AttributeError" cAttributeError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_EOFError" cEOFError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_EnvironmentError" cEnvironmentError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_FloatingPointError" cFloatingPointError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_IOError" cIOError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_ImportError" cImportError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_IndexError" cIndexError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_KeyError" cKeyError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_KeyboardInterrupt" cKeyboardInterrupt :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_MemoryError" cMemoryError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_NameError" cNameError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_NotImplementedError" cNotImplementedError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_OSError" cOSError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_OverflowError" cOverflowError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_ReferenceError" cReferenceError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_RuntimeError" cRuntimeError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_SyntaxError" cSyntaxError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_SystemExit" cSystemExit :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_SystemError" cSystemError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_TypeError" cTypeError :: Ptr (Ptr CPyObject)
foreign import ccall unsafe "&PyExc_ValueError" cValueError :: Ptr (Ptr CPyObject)
#ifdef MS_WINDOWS
foreign import ccall unsafe "&PyExc_WindowsError" cWindowsError :: Ptr (Ptr CPyObject)
#endif
foreign import ccall unsafe "&PyExc_ZeroDivisionError" cZeroDivisionError :: Ptr (Ptr CPyObject)
|