Advertisement
realever15

10302期末考07

Jun 23rd, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. package 期末考10302第七題;
  2.  
  3.  
  4. public class ErrorHandling{
  5.    
  6.     public static void main(String[] args){
  7.      boolean verify = true;
  8.      try{checkMemberID("123456789");}
  9.      catch(memberIDException e){
  10.      System.out.println("錯誤訊息:"+e.getMessage());
  11.      e.contactWith();//自訂例外類別的自定方法
  12.      verify = false;}
  13.      if(verify) System.out.println("會員證號驗證成功"); else
  14.     System.out.println("會員證號驗證失敗");
  15.      }
  16.    
  17.     public static void checkMemberID(String a)throws memberIDException
  18.     {  
  19.         if(a.length()!=5)
  20.         {
  21.             throw new memberIDException(a);
  22.         }
  23.     }
  24.    
  25. }
  26. =============================================
  27. package 期末考10302第七題;
  28.  
  29. public class memberIDException extends Exception {
  30.  
  31.     public memberIDException(String a)
  32.     {
  33.         super("會員證號: "+a+" 驗證失敗!");
  34.     }
  35.  
  36.     public void contactWith()
  37.     {
  38.         System.out.println("請聯絡服務人員: TEL:28825252");
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement