| |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
Description | |||||||||||||||||||||||||||||||
Error Reporting, glib's system for reporting errors. GErrors are used by glib to report recoverable runtime errors. This module provides functions for checking glib/gtk functions that report GErrors. It also provides functions for throwing and catching GErrors as Haskell exceptions. | |||||||||||||||||||||||||||||||
Synopsis | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
Data types | |||||||||||||||||||||||||||||||
data GError | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
type GErrorDomain = GQuark | |||||||||||||||||||||||||||||||
A code used to identify the 'namespace' of the error. Within each error domain all the error codes are defined in an enumeration. Each gtk/gnome module that uses GErrors has its own error domain. The rationale behind using error domains is so that each module can organise its own error codes without having to coordinate on a global error code list. | |||||||||||||||||||||||||||||||
type GErrorCode = Int | |||||||||||||||||||||||||||||||
A code to identify a specific error within a given GErrorDomain. Most of time you will not need to deal with this raw code since there is an enumeration type for each error domain. Of course which enumeraton to use depends on the error domain, but if you use catchGErrorJustDomain or handleGErrorJustDomain, this is worked out for you automatically. | |||||||||||||||||||||||||||||||
type GErrorMessage = String | |||||||||||||||||||||||||||||||
A human readable error message. | |||||||||||||||||||||||||||||||
Catching GError exceptions | |||||||||||||||||||||||||||||||
To catch GError exceptions thrown by Gtk2Hs functions use the catchGError* or handleGError* functions. They work in a similar way to the standard catch and handle functions. catchGError / handleGError catches all GError exceptions, you provide a handler function that gets given the GError if an exception was thrown. This is the most general but is probably not what you want most of the time. It just gives you the raw error code rather than a Haskell enumeration of the error codes. Most of the time you will only want to catch a specific error or any error from a specific error domain. To catch just a single specific error use catchGErrorJust / handleGErrorJust. To catch any error in a particular error domain use catchGErrorJustDomain / handleGErrorJustDomain | |||||||||||||||||||||||||||||||
catchGError | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
catchGErrorJust | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
catchGErrorJustDomain | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
handleGError :: (GError -> IO a) -> IO a -> IO a | |||||||||||||||||||||||||||||||
A verson of catchGError with the arguments swapped around. handleGError (\(GError dom code msg) -> ...) $ ... | |||||||||||||||||||||||||||||||
handleGErrorJust :: GErrorClass err => err -> (GErrorMessage -> IO a) -> IO a -> IO a | |||||||||||||||||||||||||||||||
A verson of handleGErrorJust with the arguments swapped around. | |||||||||||||||||||||||||||||||
handleGErrorJustDomain :: GErrorClass err => (err -> GErrorMessage -> IO a) -> IO a -> IO a | |||||||||||||||||||||||||||||||
A verson of handleGErrorJustDomain with the arguments swapped around. | |||||||||||||||||||||||||||||||
failOnGError :: IO a -> IO a | |||||||||||||||||||||||||||||||
Catch all GError exceptions and convert them into a general failure. | |||||||||||||||||||||||||||||||
throwGError :: GError -> IO a | |||||||||||||||||||||||||||||||
Use this if you need to explicitly throw a GError or re-throw an existing GError that you do not wish to handle. | |||||||||||||||||||||||||||||||
Checking for GErrors returned by glib/gtk functions | |||||||||||||||||||||||||||||||
If you are wrapping a new API that reports GErrors you should probably use propagateGError to convert the GError into an exception. You should also note in the documentation for the function that it throws GError exceptions and the Haskell enumeration for the expected glib GError domain(s), so that users know what exceptions they might want to catch. If you think it is more appropriate to use an alternate return value (eg Either/Maybe) then you should use checkGError. | |||||||||||||||||||||||||||||||
class Enum err => GErrorClass err where | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
propagateGError :: (Ptr (Ptr ()) -> IO a) -> IO a | |||||||||||||||||||||||||||||||
Glib functions which report GErrors take as a parameter a GError **error. Use this function to supply such a parameter. It checks if an error was reported and if so throws it as a Haskell exception. Example of use: propagateGError $ \gerrorPtr -> {# call g_some_function_that_might_return_an_error #} a b gerrorPtr | |||||||||||||||||||||||||||||||
checkGError :: (Ptr (Ptr ()) -> IO a) -> (GError -> IO a) -> IO a | |||||||||||||||||||||||||||||||
Like propagateGError but instead of throwing the GError as an exception handles the error immediately using the supplied error handler. Example of use: checkGError (\gerrorPtr -> {# call g_some_function_that_might_return_an_error #} a b gerrorPtr) (\(GError domain code msg) -> ...) | |||||||||||||||||||||||||||||||
Produced by Haddock version 0.8 |