Alternatives to exceptions for error handling

Jonathan M Davis newsgroup.d at jmdavisprog.com
Tue Nov 24 20:30:33 UTC 2020


On Monday, November 23, 2020 3:58:29 AM MST Jacob Carlborg via Digitalmars-d 
wrote:
> On Sunday, 22 November 2020 at 17:37:18 UTC, Roman Kashitsyn
>
> wrote:
> > In the video from DConf 2020 about @live functions
> > (https://youtu.be/XQHAIglE9CU) Walter mentioned that all @live
> > functions are nothrow.  He also thinks that exceptions are
> > obsolete.
>
> I haven't watched the video yet, but in general I think we need
> some form of error handling that more or less have the same
> semantics as the existing one. There are other ways to implement
> what looks like exception. Just look at the error handling in
> Swift, Zig and the proposal for C++ [1]. I think without any form
> of language support and syntax sugar, error handling is going to
> be a pain.
>
> [1]
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0709r0.pdf

Yeah, there are plenty of times where using a solution other than exceptions
makes more sense, but in general, exceptions are by far the cleanest and
simplest way to deal with error conditions, and I would _really_ hate to see
D move away from them as the default error handling mechanism. Personally, I
really don't care much about how they're implemented underneath the hood,
but the ability to throw an error condition up to code that handles it
higher up, allowing all of the code in between to largely ignore the error
condition is huge, and a lot of code can get pretty disgusting without that.

- Jonathan M Davis





More information about the Digitalmars-d mailing list