You are previewing Code Complete, Second Edition.

Code Complete, Second Edition

Cover of Code Complete, Second Edition by Steve McConnell Published by Microsoft Press


Exceptions are a specific means by which code can pass along errors or exceptional events to the code that called it. If code in one routine encounters an unexpected condition that it doesn't know how to handle, it throws an exception, essentially throwing up its hands and yelling, "I don't know what to do about this—I sure hope somebody else knows how to handle it!" Code that has no sense of the context of an error can return control to other parts of the system that might have a better ability to interpret the error and do something useful about it.

Exceptions can also be used to straighten out tangled logic within a single stretch of code, such as the "Rewrite with try-finally" example in goto. The basic structure of an exception ...

The best content for your career. Discover unlimited learning on demand for around $1/day.