shithub: MicroHs

ref: a898f87107b7decff2c77a6cc03023c0688728ad
dir: /lib/Control/Exception.hs/

View raw version
module Control.Exception(
  catch, try,
  throwIO,
  Exn(..)
  ) where
import Primitives
import Prelude

newtype Exn = Exn String

catch :: forall a . IO a -> (Exn -> IO a) -> IO a
catch ioa hdl = primCatch ioa (hdl . Exn)

try :: forall a . IO a -> IO (Either Exn a)
try ioa = catch (fmap Right ioa) (return . Left)

throwIO :: forall a . Exn -> IO a
throwIO (Exn s) =
  let e = error s
  in  seq e (return e)