MissingPy-0.10.5: Haskell interface to Python

MaintainerJohn Goerzen,




Maintainer : jgoerzen@complete.org Stability : provisional Portability: portable

Python low-level exception handling

Written by John Goerzen, jgoerzen@complete.org



data PyException Source

The type of Python exceptions.

General Catching

catchPy :: IO a -> (PyException -> IO a) -> IO aSource

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 aSource

Like catchPy, with the order of arguments reversed.

pyExceptions :: Exception -> Maybe PyExceptionSource

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 aSource

Like catchPy, but catches only instances of the Python class given (see doesExceptionMatch).

Exception Object Operations

formatException :: PyException -> IO PyExceptionSource

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

This call will format it.

doesExceptionMatch :: PyException -> PyObject -> IO BoolSource

Returns true if the passed PyException matches the given Python exception class or one of its subclasses. Standard Python exception classes are given in Python.Exceptions.ExcTypes.

Re-Raising Exceptions

exc2ioerror :: PyException -> IO aSource

A handler for use in catchPy or handlePy. Grabs the Python exception, describes it, and raises the description in the IO monad with fail.