2014-09-25 96 views
1

我想將錯誤代碼與例外相關聯。約定Java錯誤代碼

在這個鏈接http://www.restapitutorial.com/httpstatuscodes.html我們可以找到HTTP狀態代碼。

Java異常代碼有什麼樣的約定,比如EJBException?

+0

異常沒有錯誤代碼。他們有層次結構。 – SimY4 2014-09-25 11:47:37

+0

您可以創建自己的具有錯誤代碼的Exception子類,但不存在將異常與錯誤代碼關聯的「約定」。 – 2014-09-25 11:49:56

回答

4

不是。沒有將異常代碼附加到異常的約定。

您就可以輕鬆編寫自己的Exception做這樣的:

public class MyAppException extends Exception 
{ 
    private String errorCode; 
    public MyAppException(String errorCode, String message) 
    { 
     super(message); 
     this.errorCode = errorCode; 
    } 
    // errorCode getter & setter 
}