Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
November 20, 2018 Throwing constructors and member destructors | ||||
---|---|---|---|---|
| ||||
https://run.dlang.io/is/LdylJX Notice no "B destructor" line in stdout. Just got bitten by the assumption that my Buffer struct that transactionally aquires multiple external resources in constructor will rollback via member destructors that were successfully completed before the throw. Can I get a clarification about current semantics? Should I essentially never throw in constructors if I want to rely on scope-based RAII? And before we start a 10-page argument about the ideology of constructors, I would mostly just like to hear that this is documented somewhere, because I have certanly missed it. |
November 20, 2018 Re: Throwing constructors and member destructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Boris-Barboris | On Tuesday, 20 November 2018 at 13:01:40 UTC, Boris-Barboris wrote: > https://run.dlang.io/is/LdylJX > > Notice no "B destructor" line in stdout. > > Just got bitten by the assumption that my Buffer struct that transactionally aquires multiple external resources in constructor will rollback via member destructors that were successfully completed before the throw. > > Can I get a clarification about current semantics? Should I essentially never throw in constructors if I want to rely on scope-based RAII? > > And before we start a 10-page argument about the ideology of constructors, I would mostly just like to hear that this is documented somewhere, because I have certanly missed it. For example: https://books.google.de/books?id=5_eoCwAAQBAJ&pg=PA104&lpg=PA104&dq=dlang+rely+destructor&source=bl&ots=p33jiNUKBq&sig=yw1ymCzaRaueQ8yDDMjP75iRDYI&hl=de&sa=X&ved=2ahUKEwjosrGlhePeAhVrgM4BHcU6DEAQ6AEwBXoECAMQAQ#v=onepage&q=dlang%20rely%20destructor&f=false @book{parker2015learning, title={Learning D}, author={Parker, M.}, isbn={9781785289347}, url={https://books.google.de/books?id=5\_eoCwAAQBAJ}, year={2015}, publisher={Packt Publishing} page=104 } But yeah... I had troubles to find such a clear statement on dlang.org too... |
November 20, 2018 Re: Throwing constructors and member destructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Boris-Barboris | On Tuesday, 20 November 2018 at 13:01:40 UTC, Boris-Barboris wrote: > https://run.dlang.io/is/LdylJX > > Notice no "B destructor" line in stdout. > > Just got bitten by the assumption that my Buffer struct that transactionally aquires multiple external resources in constructor will rollback via member destructors that were successfully completed before the throw. > > Can I get a clarification about current semantics? Should I essentially never throw in constructors if I want to rely on scope-based RAII? > > And before we start a 10-page argument about the ideology of constructors, I would mostly just like to hear that this is documented somewhere, because I have certanly missed it. https://dlang.org/changelog/2.083.0.html#reboot14246 |
November 20, 2018 Re: Throwing constructors and member destructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stanislav Blinov | On Tuesday, 20 November 2018 at 13:20:08 UTC, Stanislav Blinov wrote:
> https://dlang.org/changelog/2.083.0.html#reboot14246
Wording "object" means both classes and structs?
|
November 20, 2018 Re: Throwing constructors and member destructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stanislav Blinov | On Tuesday, 20 November 2018 at 13:20:08 UTC, Stanislav Blinov wrote:
> https://dlang.org/changelog/2.083.0.html#reboot14246
Nvm, found the info in the issue tracker, thank you for the link.
|
November 20, 2018 Re: Throwing constructors and member destructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Boris-Barboris | On Tuesday, 20 November 2018 at 13:28:21 UTC, Boris-Barboris wrote:
> On Tuesday, 20 November 2018 at 13:20:08 UTC, Stanislav Blinov wrote:
>> https://dlang.org/changelog/2.083.0.html#reboot14246
>
> Nvm, found the info in the issue tracker, thank you for the link.
You're welcome. It's one of those problems that were out there for ages, and luckily it now is getting attention.
|
Copyright © 1999-2021 by the D Language Foundation