O'Reilly logo

Microsoft® Visual C#® 2008 Step by Step by John Sharp

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Trying Code and Catching Exceptions

C# makes it easy to separate the error handling code from the code that implements the main flow of the program by using exceptions and exception handlers. To write exception-aware programs, you need to do two things:

  1. Write your code inside a try block (try is a C# keyword). When the code runs, it attempts to execute all the statements inside the try block, and if none of the statements generates an exception, they all run, one after the other, to completion. However, if an error condition occurs, execution jumps out of the try block and into another piece of code designed to catch and handle the exception—a catch handler.

  2. Write one or more catch handlers (catch is another C# keyword) immediately after the try ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required