FAQ 26.02 When should a function catch an exception?

FAQ 26.02 When should a function catch an exception?

When it knows what to do with it.

There is no point having a function catch an exception if it doesn't know what to do with it. If every function had an explicit try and catch for every function it calls, two of the benefits of C++ exceptions (reduced coding and testing costs) would be lost. Errors are commonly handled several (often many) stack frames above where they are detected. Intermediate stack frames normally ignore exceptions they can't handle.

Most object-oriented systems designate some objects as controllers. Controllers typically define the policy of the system, and, because of this, they are often the objects that are best suited for implementing the system's exception-handling policy.



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