001: /*
002: * Copyright 1999-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.jxpath;
017:
018: /**
019: * Thrown in various situations by JXPath; may contain a nested exception.
020: *
021: * @author Dmitri Plotnikov
022: * @version $Revision: 1.5 $ $Date: 2004/02/29 14:17:42 $
023: */
024:
025: public class JXPathException extends RuntimeException {
026:
027: /** @serial */
028: private Throwable exception;
029:
030: /**
031: * Create a new <code>JXPathException</code> with no
032: * detail mesage.
033: */
034:
035: public JXPathException() {
036: super ();
037: this .exception = null;
038: }
039:
040: /**
041: * Create a new <code>JXPathException</code> with
042: * the <code>String </code> specified as an error message.
043: *
044: * @param msg The error message for the exception.
045: */
046: public JXPathException(String msg) {
047: super (msg);
048: this .exception = null;
049: }
050:
051: /**
052: * Create a new <code>JXPathException</code> with a
053: * given <code>Throwable</code> base cause of the error.
054: *
055: * @param e The exception to be encapsulated in a
056: * JXPathException.
057: */
058: public JXPathException(Throwable e) {
059: super (e.toString());
060: this .exception = e;
061: }
062:
063: /**
064: * Create a new <code>JXPathException</code> with the
065: * given <code>Exception</code> base cause and detail message.
066: *
067: * @param e The exception to be encapsulated in a
068: * JXPathException
069: * @param msg The detail message.
070: */
071: public JXPathException(String msg, Throwable e) {
072: super (msg);
073: this .exception = e;
074: }
075:
076: /**
077: * Return the message (if any) for this error . If there is no
078: * message for the exception and there is an encapsulated
079: * exception then the message of that exception will be returned.
080: *
081: * @return The error message.
082: */
083: public String getMessage() {
084: String message = super .getMessage();
085:
086: if (exception != null) {
087: if (message == null) {
088: if (exception.getMessage() != null) {
089: return exception.getMessage();
090: } else {
091: return exception.getClass().getName();
092: }
093: } else {
094: if (exception.getMessage() != null) {
095: return message + "; " + exception.getMessage();
096: } else {
097: return message + "; "
098: + exception.getClass().getName();
099: }
100: }
101: }
102:
103: return message;
104: }
105:
106: /**
107: * Return the actual exception (if any) that caused this exception to
108: * be raised.
109: *
110: * @return The encapsulated exception, or null if there is none.
111: */
112: public Throwable getException() {
113: return exception;
114: }
115: }
|