January 27, 2021
Hot Topics:

Object Integrity & Security: Error & Exceptions

  • By Matt Weisfeld
  • Send Email »
  • More Articles »

In this case, when the the code encounters the divide by zero, the application does not catch it and the exception finds its way to the run-time and terminates the application ungracefully as seen in Figure 1.

Click here for a larger image.

Figure 1: Generating an anomaly.

There is enough information presented when the application crashes that you can see that the system has recognized an ArithmeticException.

Because this is the first anomaly you will explore (actually an Exception), it is interesting to inspect the inheritance tree of the ArithmeticException.


ArithmeticException actually is a direct descendant of RunTimeException.

Here is the API definition for the RunTimeException:

public class RuntimeException
extends Exception

RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine.

A method is not required to declare in its throws clause any subclasses of RuntimeException that might be thrown during the execution of the method but not caught.

One of the important issues here is defined in the second sentence. For a RunTimeException, you do not have to do any preparation for it in your code. In short, this means that the compiler does not require you to provide code to catch a possible occurrence of a RunTimeException. However, this does not mean that you shouldn't—it is just that the compiler will not enforce this.

Consider the IOException as described by the Java API:


Note that in this case the IOException does not inherit from RunTimeException; it is a direct descendant of Exception. In the case of IOException, the compiler will force you to prepare for this in the sense that you will have to provide code to catch or throw the IOException. To illustrate, consider the following code in Listing 2:

import java.io.*;

class OpenFile {
   public static void main(String args[]) {

      FileInputStream fileStream = new

      DataInputStream fileIn =
         new DataInputStream(fileStream);

      while (fileIn .available() !=0) {

         System.out.println (fileIn .readLine());


      fileIn .close();



Listing 2: Generating an IOException.

When you compile this code, you receive the output in Figure 2.

Click here for a larger image.

Figure 2: Generating an IOException.

Page 2 of 6

This article was originally published on September 6, 2007

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date