[m-dev.] checked exceptions.

Peter Schachte schachte at unimelb.edu.au
Wed Feb 13 19:00:52 AEDT 2013


The trouble with using DU types for this sort of problem is that you
have to shuffle them around at every level of the call chain, and
possibly add new alternatives to many different types.  And it gets
pretty ugly for preds with multiple outputs.

There *is* a good argument for checked exceptions, which is probably the
one that inspired Paul's original post:  an exception is a way for a
pred/func to communicate with its callers, so it really is part of its
effective interface.  But on a practical level, checked exceptions are a
nuisance.

What about an opt-in checked exception system:  A mercury construct you
can wrap around a goal or expression that promises that all exceptions
have been caught, and the compiler (actually it would probably have to
be the linker) reports an error if this is not so, listing all the
uncaught exceptions?  So if your program compiles and links, you can be
sure there are no unhanded exceptions, but you don't have to jump
through hoops everywhere exceptions could happen.  And if you're not
fussed about exceptions, you don't have to use the feature at all.


On 13/02/13 13:54, giucam (contact) wrote:
> It sounds like Mercury DU-based sorts errors are supposed to be used for
> predictable or expectable exceptions, like "file not found". This is the
> equivalent of Java checked exceptions. In other words, these represent
> "normal" conditions (but not necessarily good conditions).
> 
> The risky unexpected exceptions, or the ones that should never happen
> but could theoretically happen anywhere, such as divide by zero, that's
> what exceptions in Mercury can be used for; they're effectively "program
> broke" errors, so there is no need to catch them. This is the equivalent
> of Java's unchecked exceptions. In other words, the current model is
> fine, but people need to use it properly.
> 
> On 13 Feb 2013 13:42, "Paul Bone" <paul at bone.id.au
> <mailto:paul at bone.id.au>> wrote:
> 
>     On Wed, Feb 13, 2013 at 01:10:31PM +1100, Michael Day wrote:
>     > Hi Paul,
>     >
>     >> How do people feel about checked exceptions?
>     >
>     > Vehemently opposed :)
>     >
>     > In my opinion the use of discriminated union types for return
>     values is
>     > one of the strong points of Mercury programming, and checked
>     exceptions
>     > would undermine that.
>     >
>     > Since it would be a new complex addition to the type system, it
>     needs a
>     > very strong motivation to justify adding it.
>     >
>     > What is the reason for considering this feature?
> 
>     I'm glad you asked in this way.
> 
>     Because not everone uses DU types the way they _should_ be used.  So
>     if we
>     have DU types people should use them and shouldn't need these types of
>     exceptions.
> 
>     Between your e-mail and Micheal Richter's e-mail I'm thinking that
>     something
>     more like ocamlexp is the right way to go.
> 
> 
>     --
>     Paul Bone
>     http://www.bone.id.au
>     _______________________________________________
>     developers mailing list
>     developers at lists.mercurylang.org
>     <mailto:developers at lists.mercurylang.org>
>     http://lists.mercurylang.org/listinfo/developers
> 


-- 
Peter Schachte              There is no statute of limitations on
University of Melbourne     stupidity. -- Randomly produced by a
schachte at unimelb.edu.au     computer program called Markov3.
www.cs.mu.oz.au/~schachte/
Phone: +61 3 8344 1338



More information about the developers mailing list