Can the new
operator throw an exception in real life?
And if so, do I have any options for handling such an exception apart from killing my application?
Yes new
will throw an exception if there is no more memory available, but that doesn't mean you should wrap every new in a try ... catch
. Only catch the exception if your program can actually do something about it.
If the program cannot do anything to handle that exceptional situation, what is often the case if you run out of memory, there is no use in catching the exception. If the only thing you could reasonably do is to abort the program you can as well just let the exception bubble up to top level, where it will terminate the program as well.