Checked vs unchecked exceptions

Ola Fosheim Grøstad via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 26 10:30:30 PDT 2017


On Monday, 26 June 2017 at 16:35:51 UTC, jmh530 wrote:
> Just curious: how are checked exceptions different from setting 
> nothrow as the default? Like you would have to write:
>
> void foo() @maythrow
> {
>    functionWithException();
> }
>
> So for instance, you could still use your "//shut up compiler" 
> code with the nothrow default.

I think the basic argument was that if throws-anything is the 
default expectation then people won't feel like silencing thrown 
exceptions, but allow them to propagate freely. Of course, if the 
function is marked nothrow then they still will have to silence 
any exceptions before returning, so same issue.

But, I am pretty convinced that this has more to do with tooling 
than usability. If the tooling is not created with evolving 
exceptions spec in mind then it becomes tedious to update the 
throw specification for functions higher up in the call-chain.

Another issue is that a function that takes a lambda/function as 
parameters will have to cover any exception that the parameter 
lambdas/function can throw as well. Which actually might be a 
good thing, as it forces you to think more clearly about where 
exceptions originate from: what-if-the-foreign-lambda throws an 
exception?

But it does have implications for how you work.




More information about the Digitalmars-d mailing list