
On Mon, Nov 3, 2008 at 6:24 AM, Simon Marlow
Jason Dagit wrote:
On Wed, Oct 8, 2008 at 1:19 AM, Simon Marlow
wrote: Johannes Waldmann wrote:
with 6.10, the following does not typecheck:
foo `Control.Exception.catch` \ _ -> return bar
Ambiguous type variable `e' in the constraint: `Control.Exception.Exception e'
It is probably bad programming style anyway but what is the workaround?
As long as you're aware that it is bad programming style. We deliberately didn't include an easy way to do this, because we want people to think about why they need to catch *all* exceptions (most of the time it's a bug).
Since the above is bad form, what should I be doing? Could someone please provide some examples or point me at the list of exceptions that I can catch? What about catching multiple types of exceptions?
Let's distinguish two kinds of exception handling:
Thanks. This helps a lot. Mind if I put it somewhere, such as on the wiki?
As for the kinds of exception you can catch, nowadays you can catch any type that is an instance of Exception. A good place to start is the list of instances of Exception in the docs:
http://www.haskell.org/ghc/dist/stable/docs/libraries/base/Control-Exception...
although that only contains types defined by the base package.
Others have commented on the backwards-compat issues, I don't have anything to add there.
Ah, but I had one more question that I don't think anyone has answered yet. That is, how to deal with multiple types of exceptions. Suppose, as a concrete example, that I was looking out for both ExitCode and PatternMatchFail exceptions. Maybe I'm being naive, but it seems like I'm in that situation again where I have to catch all and then check if fromException succeeds on either PatternMatchFile or ExitCode types. And then throw if it both give Nothing? Thanks! Jason