From 9618db2ab18b2ea4b9c65d15f1c690db82c98b82 Mon Sep 17 00:00:00 2001 From: Harry Garrood Date: Tue, 8 Dec 2015 23:15:50 +0100 Subject: [PATCH] Add throw (as in #8) --- docs/Control/Monad/Eff/Exception.md | 11 ++++++++++- src/Control/Monad/Eff/Exception.purs | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/Control/Monad/Eff/Exception.md b/docs/Control/Monad/Eff/Exception.md index c9658b4..45caeca 100644 --- a/docs/Control/Monad/Eff/Exception.md +++ b/docs/Control/Monad/Eff/Exception.md @@ -21,7 +21,7 @@ The type of Javascript errors ##### Instances ``` purescript -instance showError :: Show Error +Show Error ``` #### `error` @@ -74,4 +74,13 @@ main = catchException print do trace "Exceptions thrown in this block will be logged to the console" ``` +#### `throw` + +``` purescript +throw :: forall eff a. String -> Eff (err :: EXCEPTION | eff) a +``` + +A shortcut allowing you to throw an error in one step. Defined as +`throwException <<< error`. + diff --git a/src/Control/Monad/Eff/Exception.purs b/src/Control/Monad/Eff/Exception.purs index 1cad33e..786b512 100644 --- a/src/Control/Monad/Eff/Exception.purs +++ b/src/Control/Monad/Eff/Exception.purs @@ -8,6 +8,7 @@ module Control.Monad.Eff.Exception , message , throwException , catchException + , throw ) where import Prelude @@ -53,3 +54,8 @@ foreign import throwException :: forall a eff. Error -> Eff (err :: EXCEPTION | -- | trace "Exceptions thrown in this block will be logged to the console" -- | ``` foreign import catchException :: forall a eff. (Error -> Eff eff a) -> Eff (err :: EXCEPTION | eff) a -> Eff eff a + +-- | A shortcut allowing you to throw an error in one step. Defined as +-- | `throwException <<< error`. +throw :: forall eff a. String -> Eff (err :: EXCEPTION | eff) a +throw = throwException <<< error