Robustness is one of the underlying principles for all software projects and most languages provide support for making the software as robust as possible. Exception handling is one of the most common mechanisms for providing robustness and elegant way of handling exceptional situations.
void func1_recursive(int nInput)
The two above functions were executed on an Intel (R) Pentium D CPU 3.40 GHz machine with 4 GB RAM. func_with_TryCatch() took 1704 ms whereas func_without_TryCatch took 1234 ms, which is about 30% faster. Scott Meyers notes that throwing an exception is about “three orders of magnitude slower” than a normal return. Programs using exceptions are about “5-10% larger and 5-10% slower.”
As per Kevin Frei of the Visual C++ Code Generation & Tools team, Exception Handing has a performance cost which is not always measurable and depends on usage. Some of the reasons that he attributes to the cost are Usage Penalty (cost of the Exception Handling block itself), Cost of entering a protected region (the individual try catch blocks) and Cleanup Costs (finally invocation and C++ object destructors).
For more details check out: http://www.nwcpp.org/Downloads/2006/ehc.ppt
Morals of the Story
1) Use exception handling only where it is required. Do not use exceptions for normal program flow.
2) Understand the cost of using exception handling particularly in iterative functions and in functions called in a loop.