<div dir="ltr"><div>Whether thrown exceptions should be explicitly part of interface or not is still an open issue. For example, Java requires to explicitly declare the exception as part of method signature. And people complained... Then in Scala, for example, there's no such requirement. I've seen a paper showing negative consequences of implicit exceptions but I cannot find it now (I thought it was ICSE 2014...). <br><br>I found some other paper contrasting implicit vs. explicit exception flows.<br><br><a href="http://www.les.inf.puc-rio.br/opus/docs/pubs/2009/10_NelioCacho-SBES2009.pdf">http://www.les.inf.puc-rio.br/opus/docs/pubs/2009/10_NelioCacho-SBES2009.pdf</a><br><br></div><div>So, sometimes you need to handle the exception at the call site but if it's required that people simply "swallow" the exception (catch and do nothing), sometimes you need to handle them centrally in some way. I'm not sure what is best for Haskell.<br></div><div><br></div>Michal<br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Nov 9, 2014 at 8:53 AM, Roman Cheplyaka <span dir="ltr"><<a href="mailto:roma@ro-che.info" target="_blank">roma@ro-che.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 09/11/14 08:38, Michael Orlitzky wrote:<br>
> On 11/09/2014 08:11 AM, Roman Cheplyaka wrote:<br>
>> Let's say you knew what exceptions could be thrown. What would you do<br>
>> differently then?<br>
>><br>
>> Typically, if it's a command-line app and something unexpected happens,<br>
>> you simply present the error to the user. That's what exceptions do<br>
>> already without any effort from you.<br>
>><br>
><br>
> The output from the exception is usually useless, though. Rather than,<br>
><br>
>   *** Exception: EACCES<br>
><br>
> (or something similar, whatever, I'm making it up), I want to show:<br>
><br>
>   Insufficient permissions for accessing /run/<app>. This can be fixed<br>
>   by granting write and execute access on that directory to the user<br>
>   under which the application is running.<br>
><br>
> If the operation can fail in different ways -- like if the directory is<br>
> missing entirely -- I need to pattern match on the exception and display<br>
> something else.<br>
><br>
> Another example: I don't want to log a "read error" in my daemon, which<br>
> is what I'll get if I log the exception. I want to know *what* failed to<br>
> be read. Was it a file (that a cron job deleted) or a network socket<br>
> (whose connection was dropped)? I need to catch those in the code, where<br>
> I know what's being read, and what the "read error" means in context.<br>
<br>
</span>Both points are valid.<br>
<br>
Re the first, you still can achieve it by pattern-matching on<br>
exceptions. The fact that you don't know the exact set of exceptions<br>
makes it harder, but the truth is, for a non-trivial application, that<br>
set would be huge. Like, let's say you use a database. It brings in all<br>
sorts of network-related exceptions and database-level exceptions.<br>
<br>
The way to handle those, as you point out, is to augment them with<br>
high-level information ("Could not retrieve user's data"), and then<br>
maybe attach the low-level exception for debugging purposes. Again, you<br>
don't really need to know the whole set of exceptions in order to do<br>
that. Just wrap your database access function in 'try', and you'll know<br>
that whatever exception was caught, it prevented the retrieval of user's<br>
data (but keep in mind that it might be an asynchronous exception<br>
unrelated to your database activity).<br>
<span class="HOEnZb"><font color="#888888"><br>
Roman<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br></div></div>