Abstract
The CLR contains strong support for exceptions. Exceptions can be created and thrown at a point where code execution cannot continue because of some exceptional condition (usually a method failure or an invalid state). Writing exception-safe code is a difficult art to master. It would be a mistake to assume that the only tasks required when writing exception-safe code are simply throwing exceptions when an error occurs and catching them at some point. Such a view of exception-safe code is shortsighted and will lead you down a path of despair. Instead, exception-safe coding means guaranteeing the integrity of the system in the face of exceptions. When an exception is thrown, the runtime will iteratively unwind the stack while cleaning up. Your job as an exception-safe programmer is to structure your code in such a way that the integrity of the state of your objects is not compromised as the stack unwinds. That is the true essence of exception-safe coding techniques.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Rights and permissions
Copyright information
© 2010 Trey Nash
About this chapter
Cite this chapter
Nash, T. (2010). Exception Handling and Exception Safety. In: Accelerated C# 2010. Apress. https://doi.org/10.1007/978-1-4302-2538-6_7
Download citation
DOI: https://doi.org/10.1007/978-1-4302-2538-6_7
Publisher Name: Apress
Print ISBN: 978-1-4302-2537-9
Online ISBN: 978-1-4302-2538-6
eBook Packages: Professional and Applied ComputingApress Access BooksProfessional and Applied Computing (R0)