12. Exception Handling

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

And oftentimes excusing of a fault Doth make the fault the worse by the excuse.

William Shakespeare

O infinite virtue! com’st thou smiling from the world’s great snare uncaught?

William Shakespeare

Objectives

In this chapter you will learn:

• What exceptions are and how they are handled.

• When to use exception handling.

• To use try blocks ...

Get C# for Programmers, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.