keymasterviriya1150

Untitled

Dec 16th, 2015
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1.  
  2. /*จงทดสอบโปรแกรมต่อไปนี้
  3. 1.ถ้าหาก เพิ่ม System.out.println("hi"); ไปหลัง throw new Exception(); จะเกิดอะไรขึ้น
  4. 2.หากลบ  throws Exception จะเกิดอะไรขึ้น
  5. 3. แก้ไขโปรแกรมให้ดัก exception โดยห้ามใช้ try catch ใน main */
  6. public class sss {
  7.     static  void f() throws Exception
  8.     {
  9.         if(true)
  10.             throw new Exception();
  11.     }
  12.     static void g() throws Exception
  13.     {
  14.        f();
  15.     }
  16.     public static void main(String[] args) {
  17.          try
  18.         {
  19.             g();
  20.         }
  21.         catch(Exception e)
  22.         {
  23.             System.out.println(">>"+e);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment