javacodex.com
Java Examples
Java Examples
memu home questions

Throw an Exception

The following java example demonstrates how to throw an exception.

Source: (ThrowException.java)

public class ThrowException {
   public static void main(String[] args) {
      throw new IllegalArgumentException("Bad Argument");
   }
}
 

Output:

# java ThrowException 
Exception in thread "main" java.lang.IllegalArgumentException: Bad Argument
	at ThrowException.main(ThrowException.java:3)

Contact: javacodex@yahoo.com