<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 17, 2017 at 10:55 AM, Jonathon Delgado <span dir="ltr"><<a href="mailto:voldermort@hotmail.com" target="_blank">voldermort@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I'm trying to use<br>
  catch (...) (\e -> putStrLn $ show e)<br>
However, I get an error<br>
  Ambiguous type variable ‘a0’ arising from a use of ‘show’ prevents the constraint ‘(Show a0)’ from being solved.<br>
This goes away if I change the code to<br>
  catch (...) (\e -> putStrLn $ show (e::IOException))<br>
<br>
A couple of things I don't understand here:<br>
- The signature for catch begins "Exception e", and exception it "class (Typeable e, Show e) => Exception e". So why isn't show automatically available?<br>
- Why does the new code work at all? e is Exception, not IOException. What would happen if it caught a different Exception?<br></blockquote><div><br></div><div><br></div><div>In my experience, the most common thing people need is "catch all synchronous exceptions." The word "synchronous" there is the source of a lot of confusion, and relates to a complicated topic of asynchronous exceptions. My recommendation is: don't worry about that right now, use the safe-exceptions package, and switch from catch to catchAny. More details on the package are available at:</div><div><br></div><div><a href="https://haskell-lang.org/library/safe-exceptions">https://haskell-lang.org/library/safe-exceptions</a><br></div></div></div></div>