Page 63 - E-Modul PBO _Projek Ashilah
P. 63

Contoh listing program penggunaan Throws :
                          class G
                          public class G
                          {
                            public static void main(String[] args) {
                              try {
                                f();
                              }
                            catch(Exception e){
                              System.out.println(e);
                            }
                          }
                          public     static     void    f()throws      NullPointerException,
                             ArrayIndexOutOfBoundsException{
                            //implementasi method
                          throw new NullPointerException();
                            //throw new ArrayIndexOutOfBoundsException();
                            }
                          }

                           output
                           java.lang.NullPointerException


                         Contoh listing program lainnya :
                          class H
                          public class H
                          {
                            public static void main(String[] args) {
                              try
                              {
                                f();
                              }
                            catch(Exception e)
                            {
                              System.out.println(e);
                            }
                          }          static     void    f()throws      NullPointerException,
                          public
                             ArrayIndexOutOfBoundsException
                          {
                            //implementasi method
                          //throw new NullPointerException();
                            throw new ArrayIndexOutOfBoundsException();
                          }
                          }

                           output
                           java.lang.ArrayIndexOutOfBoundsException







                                                          Pemrograman Berorientasi Objek Kelas XI – Semester 2   60
   58   59   60   61   62   63   64   65   66   67   68