Drawbacks of exceptions being globally allocated

Alexandru Ermicioi alexandru.ermicioi at gmail.com
Sun Aug 15 09:10:53 UTC 2021


On Sunday, 15 August 2021 at 00:15:32 UTC, Ali Çehreli wrote:

> Even though this feature is probably never used, in D, multiple 
> exception objects are chained. For example, you can throw e.g. 
> in a destructor when there is an active exception in flight and 
> that second object gets attached to the first one in linked 
> list fashion.
>
> This may be useful in some cases but in general, these 
> colatteral exceptions don't carry much information and I don't 
> think anybody looks at them. Usually, the first one is the one 
> that explains the error case.
That is just an assumption. There could be designs where original 
exception gets wrapped in another one to comply with some 
interface, and in such cases, having entire chain visible, is 
useful. Also exceptions carry the stack trace which is useful, in 
debugging, allowing you to know possible location of the bug.

Regarding exception chaining, do you mean that it will 
automatically get chained, even without explicitly passing it as 
constructor of wrapping exception?

If so, it indeed might be best to remove such functionality, and 
just force user to do this by himself. He will then be able to 
decide whether chained exception does or does not carry any 
useful meaning.

Regards,
Alexandru




More information about the Digitalmars-d-learn mailing list