Checked vs unchecked exceptions

mckoder via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 27 09:01:37 PDT 2017


On Tuesday, 27 June 2017 at 11:40:02 UTC, Moritz Maxeiner wrote:
>>
>> It's not at all bad code to write things down that the 
>> compiler could infer, quite the opposite.
>
> Of course it is bad, because the compiler can do it better (no 
> chance for a wrong exception set sans compiler bugs) and faster 
> than you.
>
>> Writing it down signals _intent_ and the compiler can check if 
>> the implementation is matching the specification
>
> Verifying that a function meets its specification is what 
> unittests are for (asserts for runtime behaviour, static 
> asserts for types).

You might as well argue that you shouldn't have to declare the 
return type of functions because the compiler can determine that 
automatically based on the types of values you are actually 
returning. Then write unit tests to make sure that the return 
type as determined by the compiler matches what you intended.



More information about the Digitalmars-d mailing list