[Haskell-cafe] Exception handling when using STUArray
dbueno at gmail.com
Sat Mar 8 10:47:20 EST 2008
On Sat, Mar 8, 2008 at 9:54 AM, Xiao-Yong Jin <xj2106 at columbia.edu> wrote:
> > 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.
I see. In that case, you should check out the ErrorT monad transformer
it lets you throw an error conveniently using Either. It may or may
not fit your needs, but at least it's worth knowing about.
And in case you don't understand monad transformers: if you understand
the State monad, the following post is a fairly nice, minimal
explanation of monad transformers:
More information about the Haskell-Cafe