FAQ 26.01 What belongs in a try block?

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 exception. This is not wise.



C++ FAQs
C Programming FAQs: Frequently Asked Questions
ISBN: 0201845199
EAN: 2147483647
Year: 2005
Pages: 566
Authors: Steve Summit

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net