O'Reilly logo

Java Quick Syntax Reference by Mikael Olsson

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

CHAPTER 20

image

Exception Handling

Exception handling allows programmers to deal with unexpected situations that may occur in their programs. As an example, the FileReader class in the java.io package is used to open a file. Creating an instance of this class will cause Netbeans to give a reminder that the class’s constructor may throw a FileNotFoundException. Attempting to run the program will also cause the compiler to point this out.

import java.io.*;// ... FileReader in = new FileReader("Missing.file"); // error

Try-catch

To get rid of this compile-time error the exception must be caught by using a try-catch statement. This statement consists ...

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