Checked vs unchecked exceptions
Guillaume Boucher via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jun 26 10:44:15 PDT 2017
On Monday, 26 June 2017 at 16:52:22 UTC, Sebastien Alaiwan wrote:
> Checked exceptions allow a lot more precision about what types
> of exceptions a function can throw.
I totally agree that this is a problem with D right now. If you
want to catch all errors, how are you supposed to remember what
std.file.readText throws? Or std.file.mkdir?
There are two solutions to this problem that I know of:
A) Checked exceptions
B) Error codes that can't be implicitly ignored
Java uses A, Rust/Go use B. C++ uses B to some extend (e.g. in
std::experimental::filesystem).
In my opinion, option B better than A because checked exceptions
are incredibly verbose. However, both are better than nothing
(which is the current state of D right now).
It is very well possible to use option B in D. The most
convenient one is making functions nothrow and use Algebraic!(T,
ErrorCode), or, for void functions, have a parameter "ref
ErrorCode".
If all functions in Phobos would either follow that pattern or
provide an alternative nothrow overload, I would consider that
problem solved.
More information about the Digitalmars-d
mailing list