Checked vs unchecked exceptions
mckoder via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jun 26 08:40:19 PDT 2017
On Monday, 26 June 2017 at 15:15:54 UTC, Steven Schveighoffer
wrote:
>
> No, checked exceptions leads to this (maybe not for you, but
> for 90% of developers out there):
>
> void foo()
> {
> functionWithException();
> }
>
> compiler: foo throws, and you need to handle or declare the
> exceptions it throws
>
> void foo()
> {
> try {
> functionWithException();
> } catch(Exception e) {} // shut up compiler
> }
>
Why wouldn't you instead write:
void foo() throws Exception // shut up compiler
{
functionWithException();
}
That's easier, and no worse than C# even though you have defeated
checked exceptions.
Here's the point: with checked exceptions good programmers can
write good code. Without checked exceptions even good programmers
are forced to write bad code. It is impossible to prevent bad
programmers from writing bad code, so that should not even be a
goal, but enabling good programmers to write good code should be
a goal.
More information about the Digitalmars-d
mailing list