[OT] - C++ exceptions are becoming more and more problematic
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Feb 23 17:14:53 UTC 2022
On Thu, Feb 24, 2022 at 06:02:31AM +1300, rikki cattermole via Digitalmars-d wrote:
> On 24/02/2022 5:59 AM, IGotD- wrote:
> > The Herb Sutter exception/return value proposal would live alongside
> > with the old exceptions. I suspect that D would do the same thing.
>
> Yes, with the possibility of having the compiler swap the runtime
> unwinding stuff for value based where possible.
>
> Apart from some situations where you need to be able to store a class
> based exception, I don't see why it couldn't work like this.
If we had by-value exceptions, we can implement the current by-reference
exceptions simply by treating the reference to the allocated exception
as the value to be thrown. I.e.,
throw new Exception(...);
is equivalent to:
struct S {
Exception e;
}
Exception e = new Exception(...);
throwByValue S(e);
So if we implemented by-value exceptions, we don't have to break any
existing code, just treat `throw new SomeException` as syntactic sugar
for some analogue of the above.
T
--
PNP = Plug 'N' Pray
More information about the Digitalmars-d
mailing list