Monad. Eff. Exception
throwException :: forall eff a. Error -> Eff (exception :: EXCEPTION | eff) a
Throw an exception
main = do x <- readNumber when (x < 0) $ throwException $ error "Expected a non-negative number"
catchException :: forall eff a. (Error -> Eff eff a) -> Eff (exception :: EXCEPTION | eff) a -> Eff eff a
Catch an exception by providing an exception handler.
This handler removes the
main = catchException print do Console.log "Exceptions thrown in this block will be logged to the console"
try :: forall a eff. Eff (exception :: EXCEPTION | eff) a -> Eff eff (Either Error a)
Runs an Eff and returns eventual Exceptions as a
Left value. If the
computation succeeds the result gets wrapped in a
-- Notice that there is no EXCEPTION effect main :: forall eff. Eff (console :: CONSOLE, fs :: FS | eff) Unit main = do result <- try (readTextFile UTF8 "README.md") case result of Right lines -> Console.log ("README: \n" <> lines ) Left error -> Console.error ("Couldn't open README.md. Error was: " <> show error)