[Haskell-cafe] Exception handling when using STUArray

Donn Cave donn at avvanta.com
Sun Mar 9 13:12:29 EDT 2008

On Mar 8, 2008, at 10:54 PM, Don Stewart wrote:

[... replying to my poorly informed rant about exceptions ... ]

> I don't understand this complaint -- you can handle all these with  
> Control.Exception.
> xmonad catches all these things for example, in user code, to prevent
> poorly written modules throwing a pattern match exception, or calling
> 'error' and making the window manager unstable.
> Handling exceptions generated from pure code is just another part of
> making systems more robust -- and of course you can do it in Haskell.

OK, I tried this out and found that it does work, and I thought to  
`no more posting rants to haskell-cafe after late nights out with too  
wine!'  But then I changed my test error from a pattern match, to a  
and that gets past my exception handler:

	module Main (main) where
	import System (getArgs)

	ax = getArgs >>= print . head

	px = catch ax (\ e -> putStrLn ("caught this one: " ++ show e))

	main = px

Is there a way to catch it, that I'm missing?  What is the essential
difference between these errors?

If we only have to bring IO out to the locations where we want to handle
errors, then that's not so bad as I thought.

Incidentally, I also reviewed again the two Wiki pages previously
recommended in this thread, for Error and Exception, and I really
don't follow them.  I know the author is well versed in Haskell and
I'm sure he's trying to convey some valuable notion about the
difference between errors and exceptions, but it doesn't come
across and I don't think it's just me.

	Donn Cave, donn at avvanta.com

More information about the Haskell-Cafe mailing list