Checked vs unchecked exceptions
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jun 26 08:15:54 PDT 2017
On 6/25/17 1:38 PM, mckoder wrote:
> I am disappointed that D doesn't have checked exceptions.
>
> C++ and C# also don't have checked exceptions. Java has checked
> exceptions. Having programmed extensively in all these languages I can
> say with confidence that checked exceptions is the most important thing
> missing in C++ and C#. Around the time C# was released there was a lot
> of debate around the topic of checked vs unchecked exceptions and this
> created an impression that Java's use of checked exceptions was
> "controversial". In fact it is a feature every modern language should have.
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
}
So it ends up defeating the purpose. The exception is not properly
handled, either inside or outside the function.
You can get into a long discussion if you want, I'm not going there.
Bottom line: D *will not* have checked exceptions, Walter has said so
many times. If that's a deal killer, you should probably stick with
Java. Sorry, don't want to waste your time.
-Steve
More information about the Digitalmars-d
mailing list