[OT] - C++ exceptions are becoming more and more problematic

Walter Bright newshound2 at digitalmars.com
Thu Feb 24 19:14:39 UTC 2022


On 2/23/2022 11:23 PM, rikki cattermole wrote:
> 
> On 24/02/2022 6:05 PM, Walter Bright wrote:
>> One of the requirements I proposed for Phobos2 was for it to not use exceptions.
> 
> This is the sort of code we are going to end up with without a solution like 
> value type exceptions. Explicit error types and returns ala @mustuse are not 
> better than runtime exceptions, they are much worse for readability.

I agree, which makes this a challenge.

One solution is to design the return value so that failure is a valid part of 
the type. For example, searching for X can return an empty result, rather than a 
special "not found" error.

Another solution is to redesign the problem. For example, currently Phobos 
throws on an invalid Unicode character. A better way is to treat such as a 
"replacement character".


More information about the Digitalmars-d mailing list