Exceptions

Dave Menendez dave at zednenem.com
Sat Apr 8 03:02:50 EDT 2006


John Meacham writes:

> On Fri, Apr 07, 2006 at 10:00:21AM -0500, John Goerzen wrote:
> > But here's my concern.  Let's say that I wanted to, for some
> > reason, create a MultiplyByZero exception.  It should be broadly
> > considered an ArithException, and any code that catches an
> > ArithException should be able to catch my MultiplyByZero exception.
> > 
> > But the ArithException type is limited to storing errors that are
> > defined by Control.Exception.ArithException.  My MultiplyByZero is
> > not defined there, so I am out of luck.  The best I could do is
> > define a new MultiplyByZero, and catch it in my own code.  But any
> > code that others have written to catch ArithExceptions would be
> > blind to MultiplyByZero.
> 
> newtype ArithException a = ArithException a
> 
> data DivideByZero
> 
> throw (ArithException DivideByZero)
> 
> your code:
> 
> data MultiplyByZero
> throw (ArithException MultiplyByZero)

How would you use this to write a handler that captures any
ArithException?
-- 
David Menendez <zednenem at psualum.com> | "In this house, we obey the laws
<http://www.eyrie.org/~zednenem>      |        of thermodynamics!"


More information about the Haskell-prime mailing list