How to catch an exception

Ross Paterson ross@soi.city.ac.uk
Mon, 21 Jul 2003 14:39:34 +0100


On Mon, Jul 21, 2003 at 02:12:02PM +0100, Bayley, Alistair wrote:
> > module Main where
> > import Control.Exception hiding (GHC.Prelude.catch)

This hiding clause is illegal.  But anyway what you want is

> import Prelude hiding (catch)
> import Control.Exception

Prelude.catch only catches Haskell 98 exceptions; Control.Exception.catch
catches everything.

> > temp :: IO ()
> > temp = do
> >   putStrLn "line 1"
> >   ioError (AssertionFailed "my temp")

>From GHC 6.0, Exception is not the same as IOError: say throwIO instead
of ioError here.  (So GHC 6.0 flags your error as a type error.)