On Sunday, 25 December 2022 at 04:27:48 UTC+2,
gdo...@gmail.com wrote:
> is it best practice to use new(nothrow) as to not have to handle the exception?
Best practice is not to use explicit new but standard library containers.
Standard library does not use new(nothrow).
Do you have some plan what to do when allocation fails somewhere?
If no then you can just catch std::bad_alloc in main and then report that
program died because it is out of memory. If yes then you can catch at
points where it is easiest to switch to that plan.
With new(nothrow) you will have to check in code after every new.
Check that has no idea what to do if it failed or how far it is from
place where there is something to do. How is it better?
Also the exceptions that are likely never thrown typically cost lot less
performance than those checks all over code base.