Error Handling

John Meacham
Sun, 8 Dec 2002 17:05:41 -0800

you cannot catch exceptions anywhere but the IO monad, in Haskell 98
this is clear since only IO actions may throw exceptions. With imprecise
exceptions as implemented by ghc the reasoning is that what exeption is
thrown depends on the evaluation order of a given implementation.

throw (userException "foo") + throw (userException "bar")

without defining an evaluation order you cannot know which exepction is
to be thrown. catching the exception in the IO monad makes this 'okay'
since IO actions can depend on things other than its arguments (like the
evaluation order of a given implementation)


On Mon, Dec 09, 2002 at 11:35:54AM +1100, Thomas L. Bevan wrote:
> Hi,
> I'm writing a little command line app, but I have a question about error 
> handling. The code will go something like,
> main = do	(a:b:cs) <- getArgs
> 		i <- return (read a :: Int)
> 		j <- return (read b :: Int)
> 		putStr $ i + j
> How can I catch any possible cast exception? Ideally, I think I would like to 
> use the ErrorT monad as a means of handling a potentially fairly complex set 
> of inputs, but I can see no way of handling these errors neatly within that 
> monad.
> Tom
> _______________________________________________
> Haskell-Cafe mailing list

John Meacham - California Institute of Technology, Alum. -