1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package javax.mail;
21
22 /**
23 * @version $Rev: 467553 $ $Date: 2006-10-25 00:01:51 -0400 (Wed, 25 Oct 2006) $
24 */
25 public class MessagingException extends Exception {
26 // Required because serialization expects it to be here
27 private Exception next;
28
29 public MessagingException() {
30 super();
31 }
32
33 public MessagingException(String message) {
34 super(message);
35 }
36
37 public MessagingException(String message, Exception cause) {
38 super(message, cause);
39 next = cause;
40 }
41
42 public Exception getNextException() {
43 return next;
44 }
45
46 public synchronized boolean setNextException(Exception cause) {
47 if (next == null) {
48 initCause(cause);
49 next = cause;
50 return true;
51 } else if (next instanceof MessagingException) {
52 return ((MessagingException) next).setNextException(cause);
53 } else {
54 return false;
55 }
56 }
57
58 public String getMessage() {
59 Exception next = getNextException();
60 if (next == null) {
61 return super.getMessage();
62 } else {
63 return super.getMessage()
64 + " ("
65 + next.getClass().getName()
66 + ": "
67 + next.getMessage()
68 + ")";
69 }
70 }
71 }