Re:GCC 11.1
by account42 on Thursday April 29, 2021 @11:28AM
(#26982428)
> You can use new without exceptions, but you can't detect OOM then, if I'm not mistaken.
You can detect the same errors with and without exceptions - the nothrow variant returns nullptr on error. Due to overcommit, neither can be relied on to detect OOM in practice.
> If you construct your object and then acquire a resource in it later, from a function that can return an error without throwing, then you introduce complexity in the destructor and may risk errors more.
Not neccessrily, e.g. free and delete are both no-ops for nullptr.
You can detect the same errors with and without exceptions - the nothrow variant returns nullptr on error. Due to overcommit, neither can be relied on to detect OOM in practice.
> If you construct your object and then acquire a resource in it later, from a function that can return an error without throwing, then you introduce complexity in the destructor and may risk errors more.
Not neccessrily, e.g. free and delete are both no-ops for nullptr.