How do I create dynamic exceptions
Ross Paterson
ross@soi.city.ac.uk
Tue, 22 Jul 2003 15:18:50 +0100
On Tue, Jul 22, 2003 at 02:59:12PM +0100, Bayley, Alistair wrote:
> > handler :: Dynamic -> IO ()
> > handler e = do
> > case (fromDynamic e) of
> > Nothing -> putStrLn ("dynamic cast failed")
> > Just (MkExc n s) -> putStrLn ("exception: " ++ (show n) ++ " " ++ s)
>
> > main :: IO ()
> > main = catchDyn temp handler
You're catching a Dynamic wrapped as a Dynamic (catchDyn already does
fromDynamic, as indicated by its type). Change the handler to
> handler :: MyException -> IO ()
> handler (MkExc n s) = putStrLn ("exception: " ++ (show n) ++ " " ++ s)
any other dynamic exception fails through to the top level.