module Data.OpenWitness.Exception
(
Exn, unsafeExnFromString, throw, catch
) where
{
import Data.OpenWitness;
import Data.Witness;
import Data.Maybe;
import Data.Typeable;
import Control.Exception (throwDyn,catchDyn);
import Prelude(IO,String);
;
type Exn = IOWitness;
newtype ExnException = MkExnException (Any Exn);
;
unsafeExnFromString :: String -> Exn e;
unsafeExnFromString = unsafeIOWitnessFromString;
instance Typeable ExnException where
{
typeOf _ = mkTyConApp (mkTyCon "Data.OpenWitness.Exception.ExnException") [];
};
throw :: Exn e -> e -> a;
throw exn e = throwDyn (MkExnException (MkAny exn e));
catch :: IO a -> Exn e -> (e -> IO a) -> IO a;
catch foo exn catcher = catchDyn foo (\ex@(MkExnException cell) -> case matchAny exn cell of
{
Just e -> catcher e;
_ -> throwDyn ex;
});
}