
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.