[Haskell-cafe] Exception handling when using STUArray

Denis Bueno dbueno at gmail.com
Sat Mar 8 09:31:15 EST 2008

On Sat, Mar 8, 2008 at 12:29 AM, Xiao-Yong Jin <xj2106 at columbia.edu> wrote:
>  I'm using STUArray in some of my time critical number
>  crunching code.  I would like to know some way to catch the
>  exceptions raised in the ST monad, ie. ArrayException.

I am also using STUArray from some time-critical code; however, I
don't deal with ArrayException, or any exceptions for that matter.
What besides an out-of-bounds read or write might throw an
ArrayException?  If it is out-of-bounds reading or writing, surely
that indicates a bug in your program that you'd rather fix than catch
the exception, no?

Also, if you're using GHC, note that the ArrayException documentation says:

    "(NOTE: GHC currently does not throw ArrayExceptions)."

>  Looking through the Control.Exception module, I understand
>  that those functions can only be used within IO monad.  So

This isn't quite true, if I understand what you mean.  The function
throw can be used from any code
 But you must catch exceptions in the IO monad.

>  my question is, what the best way to do exception handling
>  in STUArray is.  Plus, it would be helpful if I can also
>  raise an exception in ST monad, but how?

I think what I noted in the last paragraph solves this problem.


More information about the Haskell-Cafe mailing list