I wrote this to make it a little nicer to catch IO exceptions and
convert them to ErrorT failure:

onExceptionThrowError
  :: (Error ce) =>
     IO a
  -> (String -> ce)
  -> ErrorT ce IO a
onExceptionThrowError a ce =
    liftIO (try a) >>=
      either
        (\(e :: IOException) -> throwError (ce (show e)))
        return

So now I can do, e.g.,
writeFile fp s `onExceptionThrowError` SpecificErrorConstructor ...

It works, but seems bad. Please let me know if you see ways to improve
it. Thanks.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to