Exception Handling
By Danny Kalev, C++ Pro

Traditional error handling methods such as errno are problematic in large-scale applications because they don't guarantee that runtime errors are actually caught and handled. For example, a poorly written program that calls fopen() without checking the return status might incur serious damage if the call failed for some reason. C++ introduced exception handling in 1989 to solve the shortcomings of traditional error handling methods.



Runtime errors often occur when a low-level piece of code is executing. These low-level functions cannot—and should not—try to handle the exception by themselves. Instead, they should notify their caller of the error and let it decide how to handle it. Chances are that somewhere up in the call chain, information about the exception might be lost, thereby causing the application to mishandle it or ignore it altogether.



Use exceptions to pass information about anomalous runtime conditions and to transfer control to an appropriate handler.

  
Exceptions Handling Constructs

Introduction
Exceptions Handling Constructs
Step 2: Handling Exceptions
Step 4: Handlers' Ordering

Return to Get Help with C/C++ Page

Return to Main Get Help Page


 




Find Out More



ITWorld.com: Linux Tips and Tricks: "Error Handling"

DevX 10-Minute Solution: Preventing Glitches in Signal Processing

DevX TechTip: Catch Exceptions by Reference

DevX TechTip: Unwinding the Stack

DevX TechTip: Exception Type Match

DevX TechTip: Stack Unwinding in the Event of an Uncaught Exception

DevX TechTip: Understanding Resumptive and Non-Resumptive Exception Handling Models

DevX TechTip: Add a catch(...) Statement to Your Exception Handlers' Hierarchy

All DevX 10-Minute Solutions for C/C++





TALK BACK
Throughout the years, exceptions have been criticized for their runtime overhead. Some programmers simply consider them too intricate and make do with traditional error handling techniques. What is your experience with exception handling? How useful is this feature in your applications? What about its performance?


Sponsored Links