3 ms·
There are 4 options: 1) allocation can't fail for whatever reason. So new won't ever throw. 2) allocation can fail but you do not care to handle it. Your appli
by gpderetta 8y ago
There are 4 options:
1) allocation can't fail for whatever reason. So new won't ever throw.
2) allocation can fail but you do not care to handle it. Your application will abort on an exception which is the best scenario.
3) allocation can fail and you want to handle it non locally (for example in a constructor). Exceptions work well in this scenario.
4) allocation can fail and you want to handle it locally: new(nothrow) is your friend. Remember to check for '!= nullptr'.