Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package 期末考10302第七題;
- public class ErrorHandling{
- public static void main(String[] args){
- boolean verify = true;
- try{checkMemberID("123456789");}
- catch(memberIDException e){
- System.out.println("錯誤訊息:"+e.getMessage());
- e.contactWith();//自訂例外類別的自定方法
- verify = false;}
- if(verify) System.out.println("會員證號驗證成功"); else
- System.out.println("會員證號驗證失敗");
- }
- public static void checkMemberID(String a)throws memberIDException
- {
- if(a.length()!=5)
- {
- throw new memberIDException(a);
- }
- }
- }
- =============================================
- package 期末考10302第七題;
- public class memberIDException extends Exception {
- public memberIDException(String a)
- {
- super("會員證號: "+a+" 驗證失敗!");
- }
- public void contactWith()
- {
- System.out.println("請聯絡服務人員: TEL:28825252");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement