What is an Exception?

Consider this program:

public class HelloThere {

  public static void main(String[] args) {
  
    System.out.println("Hello " + args[0]);
    
  }

}

Suppose it's run like this:

$ java HelloThere

Notice that's there's no args[0]. Here's what you get:

$ java HelloThere
java.lang.ArrayIndexOutOfBoundsException: 0
        at HelloThere.main(HelloThere.java:5)

This is not a crash. The virtual machine exits normally. All memory is cleaned up. All resources are released.


Previous | Next | Top | Cafe au Lait

Copyright 1999 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified June 22, 1999