try package:base-prelude

Similar to catch, but returns an Either result which is (Right a) if no exception of type e was raised, or (Left ex) if an exception of type e was raised and its value is ex. If any other type of exception is raised then it will be propagated up to the next enclosing exception handler.
try a = catch (Right `liftM` a) (return . Left)
The construct tryIOError comp exposes IO errors which occur within a computation, and which are not fully handled. Non-I/O exceptions are not caught by this variant; to catch all exceptions, use try from Control.Exception.
A variant of try that takes an exception predicate to select which exceptions are caught (c.f. catchJust). If the exception does not match the predicate, it is re-thrown.
A non-blocking version of putMVar. The tryPutMVar function attempts to put the value a into the MVar, returning True if it was successful, or False otherwise.
A non-blocking version of readMVar. The tryReadMVar function returns immediately, with Nothing if the MVar was empty, or Just a if the MVar was full with contents a.
A non-blocking version of takeMVar. The tryTakeMVar function returns immediately, with Nothing if the MVar was empty, or Just a if the MVar was full with contents a. After tryTakeMVar, the MVar is left empty.
Retry execution of the current memory transaction because it has seen values in TVars which mean that it should not continue (e.g. the TVars represent a shared buffer that is now empty). The implementation may block the thread until one of the TVars that it has read from has been updated. (GHC only)