A.2. Understanding the try...catch Block

If you come from a Visual Basic background, we recommend that you just forget about unstructured exception handling and learn this new approach using the try...catch statement. After you finish reading this appendix, you’ll find the structured approach much better!

A.2.1. The try...catch Statement

Using the try...catch statement is very straightforward. First we decide which code we want the error handler to monitor by placing that code inside the try block. When an exception occurs in the encapsulated code, a control goes to the catch block that handles the exception. A simple template for a try...catch block is shown in Listing A.3.

Listing A.3. A simple try...catch block
 try { // Place the code that ...

Get Graphics Programming with GDI+ 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.