Database Reference
In-Depth Information
8. When the application loads, repeat the previous steps to enter an incorrect file
name, and click Read File. You will get an exception. The difference now by
running the program through Visual Studio is that it points to the code and
exact details of the exception so you can add exception-handling code, as
shown in Figure 11-8.
Figure 11-8. Exception dialog occurs when executing code through Visual Studio
As you can see, this is very informative for a developer. It explicitly says that the file name you
provided does not exist or wasn't found, and it throws a FileNotFoundException exception.
Now, once this has occurred, there is no fix. You have to break the application by pressing Shift+F5,
which will return you to your code view, and the application will stop running. But you now know what
type of exception has occurred, so you can add code to handle it.
Note Exception handling is the main purpose of this chapter; an exercise later in the chapter will provide
detailed steps on how to do this. For now, it is important to understand a few more conceptual aspects of
exceptions.
 
Search WWH ::




Custom Search