Chapter 11 - Exceptions: When Things Go Wrong ... And They Will!

Chapter Objectives:

  • Understand Java's exception handling mechanisms.
  • Be able to use the Java try/catch statement.
  • Know how to design effective exception handlers.
  • Be able to design your own Exception subclasses.
  • Appreciate the importance that exception handling plays in program design.
  • Understand the computational overhead of exception handling.

Download PPT slides

Index:

Introduction

Handling Errors

Class Description
ArithmeticException Division by zero or some other kind of arithmetic problem
ArrayIndexOutOfBoundsException An array index is less than zero or greater than or equal to the        array's length
FileNotFoundException  Reference to a unfound file 
IndexOutOfBoundsException An array or string index out of bounds
NullPointerException  Reference to an object which has not  been instantiated
NumberFormatException Use of an illegal number format, such as when calling a method
StringIndexOutOfBoundsException  A String index less than zero or  greater than or equal to the String's  length
IllegalArgumentException Calling a method with an improper argument
    Table 11-1 Some Important Java Exceptions
 

Checked Exceptions

  public static void main(String argv[]) throws IOException {

Unchecked Exceptions

Robust Programming

Kind of Exception Kind of Program  Action to be Taken
Caught by Java Let Java handle it
Fixable condition Fix the error and resume execution
Unfixable condition Stoppable Report the error and terminate the program
Unfixable condition Not Stoppable Report the error and resume processing

Summary


Key Technical Terms:  catch block, catch an exception, checked exception,dialog box, error dialog , exception,  exception handler, finally block, method stack trace,  throw an exception, try block, unchecked exception

Suggested Exercises: 1, 2, 3, 4,  6, 9,10,  12, 13, 14