O'Reilly logo

Graphics Programming with GDI+ by Mahesh Chand

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

A.1. Why Exception Handling?

If you’ve been writing software for very long, you probably already know why you want to handle exceptions. Have you ever seen a program crash and display a weird message that doesn’t make any sense? This is what happens when developers do not handle exceptions properly. Let’s look at a simple example. Listing A.1 opens a file named c:\abc.txt.

Listing A.1. Opening a file
using System;
using System.IO;

namespace ListingA1andA2
{
  class Class1
  {
    static void Main(string[] args)
    {
      File.Open("c:\\abc.txt", FileMode.Open);
    }
  }
}

What if the file does not exist? We get the error message shown in Figure A.1. We are fortunate that CLR handles so much for us because otherwise this error message could have been a lot worse. ...

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