It is common sense to take a method and try it. If it fails, admit it frankly and try another. But above all, try something. Franklin Delano Roosevelt
It is common sense to take a method and try it. If it fails, admit it frankly and try another. But above all, try something.
Franklin Delano Roosevelt
O! throw away the worser part of it, And live the purer with the other half. William Shakespeare
O! throw away the worser part of it, And live the purer with the other half.
William Shakespeare
If they're running and they don't look where they're going I have to come out from somewhere and catch them. J. D. Salinger
If they're running and they don't look where they're going
I have to come out from somewhere and catch them.
J. D. Salinger
And oftentimes excusing of a fault Doth make the fault the worse by the excuse. William Shakespeare
And oftentimes excusing of a fault Doth make the fault the worse by the excuse.
O infinite virtue! com'st thou smiling from the world's great snare uncaught? William Shakespeare
O infinite virtue! com'st thou smiling from the world's great snare uncaught?
In this chapter you will learn:
What exceptions are and how they are handled.
When to use exception handling.
To use TRy blocks to delimit code in which exceptions might occur.
To Throw exceptions to indicate a problem.
To use Catch blocks to specify exception handlers.
To use the Finally block to release resources.
The .NET exception class hierarchy.
Exception properties.
To create user-defined exceptions.
Outline
12.1 Introduction12.2 Exception Handling Overview12.3 Example: Divide by Zero Without Exception Handling12.4 Example: Handling DivideByZeroExceptions and FormatExceptions12.4.1 Enclosing Code in a try Block12.4.2 Catching Exceptions12.4.3 Uncaught Exceptions12.4.4 Termination Model of Exception Handling12.4.5 Flow of Control When Exceptions Occur12.5 .NET Exception Hierarchy12.5.1 Classes ApplicationException and SystemException12.5.2 Determining Which Exceptions a Method Throws12.6 Finally Block12.7 Exception Properties12.8 User-Defined Exception Classes12.9 Wrap-Up
12.1 Introduction
12.2 Exception Handling Overview
12.3 Example: Divide by Zero Without Exception Handling
12.4 Example: Handling DivideByZeroExceptions and FormatExceptions
12.4.1 Enclosing Code in a try Block12.4.2 Catching Exceptions12.4.3 Uncaught Exceptions12.4.4 Termination Model of Exception Handling12.4.5 Flow of Control When Exceptions Occur
12.4.1 Enclosing Code in a try Block
12.4.2 Catching Exceptions
12.4.3 Uncaught Exceptions
12.4.4 Termination Model of Exception Handling
12.4.5 Flow of Control When Exceptions Occur
12.5 .NET Exception Hierarchy
12.5.1 Classes ApplicationException and SystemException12.5.2 Determining Which Exceptions a Method Throws
12.5.1 Classes ApplicationException and SystemException
12.5.2 Determining Which Exceptions a Method Throws
12.6 Finally Block
12.7 Exception Properties
12.8 User-Defined Exception Classes
12.9 Wrap-Up