"Denis Bueno" <[EMAIL PROTECTED]> writes: > On Sat, Mar 8, 2008 at 12:29 AM, Xiao-Yong Jin <[EMAIL PROTECTED]> 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?
In my case, because I choose a index of the array according to certain value in the array, if there is NaN or Infinity in the array, the code breaks. So I guess, to fix the code, I would probably use isNaN/isInfinite and throw an exception when that happens. > 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. Thanks for the clarification. I didn't read the documentation carefully. I'll experiment on `throw', right now. Xiao-Yong -- c/* __o/* <\ * (__ */\ < _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe