Using try Blocks and catch Blocks
Figuring out where to put your try blocks is probably the hardest part of using exceptions; it is not always obvious which actions might raise an exception. The next question is where to catch the exception. It might be that you'll want to throw all memory exceptions where the memory is allocated, but you'll want to catch the exceptions high in the program where you deal with the user interface.
When trying to determine try block locations, look to where you allocate memory or use resources. Other things to look for are out-of-bounds errors, illegal input, and so forth.
Catching Exceptions
Here's how catching exceptions works: When an exception is thrown, the call stack is examined. The call stack is the list ...
Get Sams Teach Yourself C++ in 24 Hours, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.