OSDN Git Service

imported from subversion repository
[xerial/xerial-core.git] / src / main / java / org / xerial / core / XerialException.java
1 /*--------------------------------------------------------------------------\r
2  *  Copyright 2004 Taro L. Saito\r
3  *\r
4  *  Licensed under the Apache License, Version 2.0 (the "License");\r
5  *  you may not use this file except in compliance with the License.\r
6  *  You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  *  Unless required by applicable law or agreed to in writing, software\r
11  *  distributed under the License is distributed on an "AS IS" BASIS,\r
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  *  See the License for the specific language governing permissions and\r
14  *  limitations under the License.\r
15  *--------------------------------------------------------------------------*/\r
16 //--------------------------------------\r
17 // XerialJ\r
18 //\r
19 // XerialException.java\r
20 // Since: 2004/12/21\r
21 //\r
22 // $URL: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core/src/main/java/org/xerial/core/XerialException.java $\r
23 // $Author:leo $\r
24 //--------------------------------------\r
25 package org.xerial.core;\r
26 \r
27 import org.xerial.json.JSONErrorCode;\r
28 \r
29 /**\r
30  * Base exception class for Xerial Project.\r
31  * \r
32  * XerialException must be instantiated with an error code that implements\r
33  * {@link ErrorCode} interface. To add your own error codes for the use with\r
34  * {@link XerialException}, you have to implement the {@link ErrorCode}\r
35  * interface. See examples of error codes: {@link XerialErrorCode},\r
36  * {@link JSONErrorCode}, etc.\r
37  * \r
38  * @author leo\r
39  * \r
40  */\r
41 public class XerialException extends Exception\r
42 {\r
43 \r
44     private static final long serialVersionUID = 1L;\r
45 \r
46     protected final ErrorCode errorCode;\r
47 \r
48     public XerialException(XerialException e) {\r
49         super(e.getErrorMessage());\r
50         this.errorCode = e.errorCode;\r
51     }\r
52 \r
53     public XerialException(ErrorCode errorCode) {\r
54         super();\r
55         this.errorCode = errorCode;\r
56     }\r
57 \r
58     public XerialException(ErrorCode errorCode, String message, Throwable cause) {\r
59         super(message, cause);\r
60         this.errorCode = errorCode;\r
61     }\r
62 \r
63     public XerialException(ErrorCode errorCode, String message) {\r
64         super(message);\r
65         this.errorCode = errorCode;\r
66     }\r
67 \r
68     public XerialException(ErrorCode errorCode, Throwable cause) {\r
69         super(cause);\r
70         this.errorCode = errorCode;\r
71     }\r
72 \r
73     @SuppressWarnings("unchecked")\r
74     public <T> T getErrorCode() {\r
75         return (T) errorCode;\r
76     }\r
77 \r
78     @Override\r
79     public String getMessage() {\r
80         return ExceptionHelper.getMessage(errorCode, super.getMessage());\r
81     }\r
82 \r
83     private String getErrorMessage() {\r
84         return super.getMessage();\r
85     }\r
86 \r
87 }\r