O'Reilly logo

C++ FAQs, Second Edition by Mike Girou, Greg Lomow, Marshall Cline

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 26. Exception Tactics

FAQ 26.01 What belongs in a try block?

Code that may throw an exception from which this function might be able to recover.

If the code called from a try block cannot throw an exception, then there is no need for the try block. Similarly, if the code called from a try block can throw exceptions but this function cannot recover from the exceptions, then there is no point in catching the exception and no point in putting the code in a try block.

Simply put, a function shouldn't worry about things that it can't fix. The important message here is that try…catch is not like old-fashioned error codes. Programmers who don't realize the differences put a try block around every call to every routine that could throw an ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required