Skip to content

Instantly share code, notes, and snippets.

@UnkindPartition
Created December 4, 2012 09:10
Show Gist options
  • Save UnkindPartition/4202071 to your computer and use it in GitHub Desktop.
Save UnkindPartition/4202071 to your computer and use it in GitHub Desktop.
Exception secrecy
-- 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