ContentsIndex
Python.Exceptions
Portability portable
Stability provisional
Maintainer jgoerzen@complete.org
Contents
Types
General Catching
Catching of specific Python exceptions
Exception Object Operations
Re-Raising Exceptions
Description

Python low-level exception handling

Written by John Goerzen, jgoerzen@complete.org

Synopsis
data PyException = PyException {
excType :: PyObject
excValue :: PyObject
excTraceBack :: PyObject
excFormatted :: String
}
catchPy :: IO a -> (PyException -> IO a) -> IO a
handlePy :: (PyException -> IO a) -> IO a -> IO a
pyExceptions :: Exception -> Maybe PyException
catchSpecificPy :: PyObject -> IO a -> (PyException -> IO a) -> IO a
formatException :: PyException -> IO PyException
doesExceptionMatch :: PyException -> PyObject -> IO Bool
exc2ioerror :: PyException -> IO a
Types
data PyException
The type of Python exceptions.
Constructors
PyException
excType :: PyObjectException type
excValue :: PyObjectException value
excTraceBack :: PyObjectTraceback
excFormatted :: StringFormatted for display
Instances
Show PyException
Typeable PyException
General Catching
catchPy :: IO a -> (PyException -> IO a) -> IO a

Execute the given IO action.

If it raises a PyException, then execute the supplied handler and return its return value. Otherwise, process as normal.

handlePy :: (PyException -> IO a) -> IO a -> IO a
Like catchPy, with the order of arguments reversed.
pyExceptions :: Exception -> Maybe PyException
Useful as the first argument to catchJust, tryJust, or handleJust. Return Nothing if the given exception is not a PyException, or the exception otherwise.
Catching of specific Python exceptions
catchSpecificPy :: PyObject -> IO a -> (PyException -> IO a) -> IO a
Like catchPy, but catches only instances of the Python class given (see doesExceptionMatch).
Exception Object Operations
formatException :: PyException -> IO PyException

When an exception is thrown, it is not immediately formatted.

This call will format it.

doesExceptionMatch :: PyException -> PyObject -> IO Bool
Returns true if the passed PyException matches the given Python exception class or one of its subclasses. Standard Python exception classes are given in ExcTypes.
Re-Raising Exceptions
exc2ioerror :: PyException -> IO a
A handler for use in catchPy or handlePy. Grabs the Python exception, describes it, and raises the description in the IO monad with fail.
Produced by Haddock version 0.6