
I've noticed some interesting behaviour:
Prelude Control.Exception> try (return (error "e"))
Prelude Control.Exception> it
Right *** Exception: e
It would appear that when the result of this function is evaluated, the
exception fires during evaluation, after the try is out of scope. I suppose
it makes some kind of twisted sense due to lazy evaluation going on, but it
is certainly a gotcha.
I did notice this:
Prelude Control.Exception> try (return $! (error "e"))
Prelude Control.Exception> it
Left e
Seemingly, forcing strict evaluation on the argument of return fixes the
problem by making sure that any exception that *can* happen, *does* happen.
However, this code from my COM wrapper:
--[id(3)] HRESULT XmlQuery([in,string] BSTR query, [out,retval]BSTR* xml);
xmlQuery :: String -> State -> IO String
xmlQuery qry (State st) = do
db <- readIORef st
Control.Exception.catch (return $! (XMLDatabase.xmlQuery qry db))
(\ _ -> return "