Raymond Chen's take on so-called zero cost exceptions

Araq rumpf_a at web.de
Tue Mar 1 06:50:54 UTC 2022


On Tuesday, 1 March 2022 at 06:44:05 UTC, H. S. Teoh wrote:
> If error codes are somehow fundamentally more efficient, why 
> can't the compiler just rewrite throwing functions into 
> functions that return error codes, with the compiler inserting 
> error code checks into the caller as needed?

Exactly. It's entirely feasible. And it is what Swift does: 
https://www.mikeash.com/pyblog/friday-qa-2017-08-25-swift-error-handling-implementation.html

(It's not universally faster than table based exceptions but it 
seems preferable for embedded devices.)


More information about the Digitalmars-d mailing list