home *** CD-ROM | disk | FTP | other *** search
/ Java Certification Exam Guide / McGrawwHill-JavaCertificationExamGuide.iso / pc / Web Links and Code / rev / chap8 / q6.java < prev    next >
Encoding:
Java Source  |  1997-05-08  |  583 b   |  29 lines

  1. class B {
  2.    public static void main(String[] args) {
  3.       B b = new B();
  4.       b.test(args);
  5.    }
  6.  
  7.    void test(String[] args) {
  8.       String s;
  9.  
  10.       if (args.length == 0)
  11.          s = new String("don't throw");
  12.       else
  13.          s = args[0];
  14.  
  15.       try {
  16.          method(s);
  17.          System.out.println("no exception");
  18.       } catch (MyException e) {
  19.          System.out.println("caught");
  20.       }
  21.    }
  22.    void method(String s) throws MyException {
  23.       if (s.equals("throw"))
  24.          throw new MyException();
  25.       else
  26.          return;
  27.    }
  28. }
  29.