Handling Unchecked Exceptions

Unchecked exceptions do not require the user of the class to handle exceptions at compile time, but rather at runtime. For this reason, they extend the RuntimeException class as opposed to the Exception class. If an exception is not handled by the time it reaches the main() method, the JVM will print the stack trace and shut down. In the following message, the ArrayIndexOutOfBoundsException was not handled in the test() or the main() methods, and therefore, the program was terminated.

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
	at lab10.Lab10.test(Lab10.java:23)
	at lab10.Lab10.main(Lab10.java:11)

You may chose to handle the exception by catching it using a try/catch block to exit the program more elegantly.
public static void main(String args[]){
   try{
      System.out.println(args[0]);
   }
   catch(ArrayIndexOutOfBoundsException e){
      // handle the exception generated in the try block
      System.err.println("The program requires at least one "
      	+ "command line argument");
      System.exit(1);
   }
}