1 /*--------------------------------------------------------------------------
\r
2 * Copyright 2004 Taro L. Saito
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
19 // XerialException.java
\r
20 // Since: 2004/12/21
\r
22 // $URL: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core/src/main/java/org/xerial/core/XerialException.java $
\r
24 //--------------------------------------
\r
25 package org.xerial.core;
\r
27 import org.xerial.json.JSONErrorCode;
\r
30 * Base exception class for Xerial Project.
\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
41 public class XerialException extends Exception
\r
44 private static final long serialVersionUID = 1L;
\r
46 protected final ErrorCode errorCode;
\r
48 public XerialException(XerialException e) {
\r
49 super(e.getErrorMessage());
\r
50 this.errorCode = e.errorCode;
\r
53 public XerialException(ErrorCode errorCode) {
\r
55 this.errorCode = errorCode;
\r
58 public XerialException(ErrorCode errorCode, String message, Throwable cause) {
\r
59 super(message, cause);
\r
60 this.errorCode = errorCode;
\r
63 public XerialException(ErrorCode errorCode, String message) {
\r
65 this.errorCode = errorCode;
\r
68 public XerialException(ErrorCode errorCode, Throwable cause) {
\r
70 this.errorCode = errorCode;
\r
73 @SuppressWarnings("unchecked")
\r
74 public <T> T getErrorCode() {
\r
75 return (T) errorCode;
\r
79 public String getMessage() {
\r
80 return ExceptionHelper.getMessage(errorCode, super.getMessage());
\r
83 private String getErrorMessage() {
\r
84 return super.getMessage();
\r