"Fail: unknown exception"
George Russell
ger at informatik.uni-bremen.de
Tue Jan 6 12:44:47 EST 2004
Simon Marlow wrote:
>
>
>>This has to be one of the most irritating ways a program can
>>fall over.
>>Can't the Haskell RTS try just a /little/ harder to help the poor
>>programmer? For example by saying what sort of exception it is, and
>>(if it's a dynamic exception) what type it has?
>
>
> An "unknown exception" is a dynamic exception. GHC just uses the
> ordinary instance of Show on Exception to print out the value of an
> exception, and it so happens that all it prints out for a dynamic
> exception is "unknown exception".
>
> Arguably the show instance should print out the type too. It could; I
> just looked into it and unfortunately there's an annoying module loop in
> the libraries which means doing this would entail some restructuring.
>
> Why can't GHCi just print out the type itself? Because it has to be
> done in the context of the interpreted program, which means GHCi would
> have to compile a little snippet of code to show the exception.
> Annoying, but doable.
Alternative suggestion: could the RTS provide a global variable containing a value of
type Maybe (Exception -> Maybe String)? If set, this would be called whenever the
RTS attempted to display an uncaught exception, and the String returned if any displayed.
I know this is really an awful hack but (a) it's what I want; (b) you didn't
expect exceptions to be nice did you?; (c) wouldn't it avoid the above restructuring
and GHCi hackery?
We could argue the details of the value. For example storing a list of functions with
tags [(String,Exception -> Maybe String)] to be tried in order would allow the user
to selectively delete particular descriptive functions. This hardly seems necessary,
but in any case it might be better to restrict the visible user interface to
addGlobalExceptionDescriber :: (Exception -> Maybe String) -> IO ()
to allow for future developments ...
More information about the Glasgow-haskell-users
mailing list