Alternatives to exceptions for error handling
Roman Kashitsyn
romankashicin at gmail.com
Sun Nov 22 17:37:18 UTC 2020
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've been programming in Google's C++, Go & Rust for quite a few
years and I couldn't agree more with this assessment. Error
handling is a very important part of program engineering, and
having errors reflected in function return types is very useful
in practice. This helps a lot with constructing correct programs.
So my question is: does/will D provide support for alternative
approaches to error handling? In practice, this typically
includes 2 things:
1. A sum type that contains either a result or an error. Like
Result in Rust or Expected that Andrei proposed for C++. It's
easy to implement in D, but having this in Phobos would be nice.
2. Some kind of syntactic sugar for propagating errors upstream
(? macro in Rust, check/handle proposal in Go
https://go.googlesource.com/proposal/+/master/design/go2draft-error-handling.md, an ugly macro in C++, etc.).
More information about the Digitalmars-d
mailing list