[Haskell] Better Exception Handling
John Goerzen
jgoerzen at complete.org
Tue Nov 23 10:25:10 EST 2004
On Tue, Nov 23, 2004 at 04:12:52PM +0100, Johannes Waldmann wrote:
>
> >The other annoying thing is forcing it to run in the IO monad.
>
> necessarily so, since Haskell has non-strict semantics
> so it's not so clear when an exception is actually raised
> (you might have left the block that textually contained the offending
> expression , and the exception handler, a long time ago)
I'm not sure I follow that.
Let's say I have a function:
myfunc :: String -> Int
This does some sort of string parsing and returns an Int. Or it may
raise an exception if it couldn't parse the string. But it would do
that every time.
Now, let's say we have a non-IO catchJust. Of course, if we never need
the value, we never run the function -- or catchJust. If we do need the
value, we run the function in the context of catchJust. If it raises
our exception, catchJust handles it and returns some default. If it
raises no exception, it's the same as having no handler at all. And if
it raises some other exception, it's also the same as having no handler
at all.
So what am I missing here?
More information about the Haskell
mailing list