ThrowExceptionDemo.java

Download ThrowExceptionDemo.java

 1: public class ThrowExceptionDemo {
 2: 
 3:   public static String foo ( int num ) throws IllegalArgumentException {
 4:     if ( num < 0 )
 5:        throw new IllegalArgumentException( "Oops!" );
 6:     return "Yippie!";
 7:   }
 8: }
 9: 
10: class ThrowExceptionDemoTest {
11:   public static void main ( String [] args ) {
12:     String result = null;
13:     try {
14:       result = ThrowExceptionDemo.foo( -1 );
15:     } catch ( IllegalArgumentException iae) {
16:        System.out.println( "You ARE the weakest link, good-bye!" );
17:     }
18:     System.out.println( result );
19:   }
20: }