7.1 Exceptions

In computer programs, things can go wrong. For instance, you try to open a file, which does not exist, or you try to divide two numbers, but the denominator happens to be zero. In the object-oriented programming language Java, an object is created upon a fault or mistake during run time: an Exception is thrown.

An Example

We create a straightforward applet in which integer division is demonstrated. If the denominator b is 0, then a problem occurs: an exception is generated by the program.

Somewhere, probably in the Java console, you are notified about the exception. An other problem you can easily create, is to enter a non-integer in one of the input fields. Try any character.

  1. Handling Exceptions
  2. Errors, Exceptions and the class Throwable
  3. Runtime Exceptions
  4. How to Throw Your Own Exception