13. Exception Handling: A Deeper Look

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

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


In this chapter you’ll learn:

• What exceptions are and how they’re 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. ...

Get Visual C#® 2012: How to Program, Fifth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.