bluefin-0.0.0.0
Safe HaskellNone
LanguageHaskell2010

Bluefin.Exception

Synopsis

Handle

data Exception e (ex :: Effects) Source #

Handle to an exception of type e

Instances

Instances details
e :> es => MonadFail (EffReader (Exception String e) es) 
Instance details

Defined in Bluefin.Internal

Methods

fail :: String -> EffReader (Exception String e) es a #

Handlers

try Source #

Arguments

:: forall e (es :: Effects) a. (forall (ex :: Effects). Exception e ex -> Eff (ex :& es) a) 
-> Eff es (Either e a)

Left if the exception was thrown, Right otherwise

>>> runPureEff $ try $ \e -> do
      throw e 42
      pure "No exception thrown"
Left 42

handle Source #

Arguments

:: forall e (es :: Effects) a. (e -> Eff es a)

If the exception is thrown, apply this handler

-> (forall (ex :: Effects). Exception e ex -> Eff (ex :& es) a) 
-> Eff es a 

handle, but with the argument order swapped

>>> runPureEff $ handle (pure . show) $ \e -> do
      throw e 42
      pure "No exception thrown"
"42"

catch Source #

Arguments

:: forall e (es :: Effects) a. (forall (ex :: Effects). Exception e ex -> Eff (ex :& es) a) 
-> (e -> Eff es a)

If the exception is thrown, apply this handler

-> Eff es a 

Effectful operations

throw Source #

Arguments

:: forall (ex :: Effects) (es :: Effects) e a. ex :> es 
=> Exception e ex 
-> e

Value to throw

-> Eff es a 
>>> runPureEff $ try $ \e -> do
      throw e 42
      pure "No exception thrown"
Left 42
>>> runPureEff $ try $ \e -> do
      pure "No exception thrown"
Right "No exception thrown"