Chapter 9
Handling Exceptions
IN THIS CHAPTER
Seeing what to do when bad things happen to good programs
Finding out all about exceptions
Using try, catch, and finally
This chapter is about what happens when Java encounters an error situation that it can’t deal with. Being an object-oriented programming language, Java handles errors by using special exception objects that are created when an error occurs. In addition, Java has a special statement called the try statement that you must use to deal with exception objects. In this chapter, you find all the gory details of working with exception objects and try statements.
Understanding Exceptions
An exception is an object that’s created when an error occurs in a Java program and Java can’t automatically fix the error. The exception object contains information about the type of error that occurred. The most important information — the cause of the error — is indicated by the name of the exception class used to create the exception. You usually don’t have to do anything with an exception object other than figure out which one you have.
Each type of exception that can occur is represented by a different exception class. Here are some ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access