The documentation says:
The throwIO variant should be used in preference to throw to raise an exception within the IO monad because it guarantees ordering with respect to other IO operations, whereas throw does not.
I'm still confused after reading it. Is there an example to show that throw will cause a problem whereas throwIO will not?
Additional question:
Is the following statement correct?
- If
throw
is being used to throw an exception in an IO, then the order of the exception is not guaranteed. - If
throw
is being used to throw an exception in a non-IO value, then the order of the exception is guaranteed.
If I need to throw an exception in a Monad Transformer, which I have to use throw
instead of throwIO
, does it guarantee the order of the exception?