Catching errors thrown with `error`?

either, exception, haskell

Solution

There is no spoon. You didn't hear it from me.

For this particular example, though, you should use `reads` instead.

Problem

There are some stdlib functions that throw errors on invalid input. For example: ``` Prelude> read "1o2" :: Int *** Exception: Prelude.read: no parse ``` I would like to wrap it to return a `Either e a` instead. How can I do that?

Original source