Phobos 3 Discussion Notes - 02-01-2024

H. S. Teoh hsteoh at qfbox.info
Sun Feb 4 13:27:41 UTC 2024


On Sun, Feb 04, 2024 at 05:35:02AM -0700, Jonathan M Davis via Digitalmars-d wrote:
> On Sunday, February 4, 2024 3:13:39 AM MST ryuukk_ via Digitalmars-d wrote:
> > EH is evil, some platforms has banned it completly (apple), and
> > microsoft is all in rust, they are rewritting their C# application
> > in Rust too, not just C++, it is an inferior design
[...]
> A number of us do not agree with you, and I for one never will. For
> many situations, exceptions are by far the best error handling
> mechanism that there is.

Exceptions are like the GC: they free your APIs from being littered with
error-handling paraphrenalia that crowd out the actual business logic.
Just like not having the GC forces your code and APIs to be crowded with
memory-management paraphrenalia. Both memory management and
error-handling are secondary concerns; the primary concern is actually
making progress in your problem domain: doing what the code set out to
achieve in the first place. As such, code should be focused as much as
possible on the business logic rather than have secondary concerns
occupy most of the space. Ideally, the main code should *only* express
the business logic; memory management and error-handling should be done
in a footnote rather than in the main body of the code.

Try/catch blocks let you do this to a large extent; whereas having to
manually check error codes or unwrap error sumtypes just adds excessive
verbosity to the primary logic, which makes code more tedious to write,
harder to read, and less maintainable as a result.

I suspect, though, that most objections to EH are directed primarily at
the specific implementation of it using libunwind like in C++, rather
than the concept itself of EH. That part I agree with: the way EH is
implemented could be done better. But as far as the concept is concerned
it's fine, and trying to get rid of it is just silly.


T

-- 
The easy way is the wrong way, and the hard way is the stupid way. Pick one.


More information about the Digitalmars-d mailing list