4.24. MarshalError

The module MarshalError provides language independent routines for converting error conditions of external functions into Haskell IO monad exceptions.

throwIf     :: (a -> Bool) -> (a -> String) -> IO a       -> IO a
throwIf_    :: (a -> Bool) -> (a -> String) -> IO a       -> IO ()
throwIfNeg  :: (Ord a, Num a) 
	    =>                (a -> String) -> IO a       -> IO a
throwIfNeg_ :: (Ord a, Num a)
	    =>                (a -> String) -> IO a       -> IO ()
throwIfNull ::                String        -> IO (Ptr a) -> IO (Ptr a)

void        :: IO a -> IO ()

The first two arguments to throwIf are a predicate yielding True if an error condition is met and a function that computes from that error condition an error message, which will be included in the raised IO exception. The third argument is an IO action whose result will be tested for the aforementioned error condition. If no error occurs, the result of the action is the result of the whole operation. The variant throwIf_ works exactly in the same way, but discards the result of the IO action in any case.

The two functions throwIfNeg and throwIfNeg_ instantiate throwIf and throwIf_ with a predicate testing for a negative result. Similarly, throwIfNull instantiates throwIf with a predicate testing for a Ptr.nullPtr (Section 4.29).

Finally, the function void discards the result of an IO action.