[Haskell-cafe] Exception handling when using STUArray

Henning Thielemann lemming at henning-thielemann.de
Sat Mar 8 15:33:39 EST 2008


On Sat, 8 Mar 2008, Denis Bueno wrote:

> 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?

Another instance of mixing up exceptions and errors in the Haskell 
libraries.
   http://www.haskell.org/haskellwiki/Error
   http://www.haskell.org/haskellwiki/Exception


> 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
> (http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html).
> 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