As with any C++, the following universal rule applies:
Catch all exceptions that can possibly be thrown, and only if you can respond to them meaningfully.
You can catch all other exceptions (...
) as well and create a log message or something like that, but then you have to rethrow them (throw;
). If there's nothing you can do in your code other than abort some operation, then you don't need to handle the exception. Let it bubble up to a place where it can be used meaningfully.
In your code, you will have to allow at least for memory allocation errors (std::bad_alloc
), so you could check for those, if that makes sense. But again, if you don't know what you're catching, there's not much you can do with what you catch.
Saying your "program cannot fail" can only mean so much. Ultimately, if you have an allocation error in a top-level data structure, there's nothing you can do. The best scenario I can imagine is if your main function processes some data in a loop; in that case, you can put a universal try block around the loop, and in case of an exception you just move on to the next round. But I would count that as an instance of being able to "handle an exception meaningfully", so that's just a special case of the above. In general, while you may want to wrap your entire main function in a try block, you'll just have to accept that in the ultimate catch-all case you don't have much of a choice but to abort the program.