Thursday, January 30, 2014

How to throw an exception in java?

Source:
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)

Blog Archive