[Haskell-beginners] Generic exception available?

Daniel Fischer daniel.is.fischer at googlemail.com
Sun May 15 20:23:20 CEST 2011


On Sunday 15 May 2011 18:53:32, Christopher Howard wrote:
> I have one spot in some code where I just want to raise an exception
> that contains the message "Database is formatted incorrectly." Is there
> some kind of generic way to throw that (like, e.g., in Ruby you just
> call 'raise "exception message"'. In this case, I don't particularly
> want to take the time to think about creating an Exception type or
> finding a suitable one.

Well, the simple thing would be calling

error "Database is formatted incorrectly."

which raises an exception of type ErrorCall.
If you don't know what type of exception you should throw, ErrorCall might 
fit.

> 
> (BTW: Is there a hierarchical list of standard Haskell Exception
> instances somewhere?)

There's no hierarchy, either a type is an instance of Exception or not, 
since there's no inheritance, there's no hierarchy (unless you count the 
universal Exception-wrapper SomeException, in which case we'd have a two-
level hierarchy with that on top).

The haddock docs for the Exception class in Control.Exception [to be found 
locally, on hackage, or on the ghc page] list the known instances.



More information about the Beginners mailing list