Created
December 4, 2012 09:10
-
-
Save UnkindPartition/4202071 to your computer and use it in GitHub Desktop.
Exception secrecy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- In response to http://existentialtype.wordpress.com/2012/12/03/exceptions-are-shared-secrets/ | |
{-# LANGUAGE DeriveDataTypeable #-} | |
module MyException | |
( Secret | |
, MyException | |
, throwMyException | |
, handleMyException | |
) where | |
import Data.Typeable | |
import Control.Exception | |
type Secret = Int | |
newtype MyException = MyException { unMyException :: Secret } | |
deriving Typeable | |
instance Show MyException where | |
show _ = "<secret>" | |
instance Exception MyException | |
throwMyException :: Secret -> a | |
throwMyException = throw . MyException | |
handleMyException :: (Secret -> IO a) -> IO a -> IO a | |
handleMyException h = handle $ h . unMyException |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment