Skip to content

Package: MessagingException

MessagingException

nameinstructionbranchcomplexitylinemethod
MessagingException()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
MessagingException(String)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
MessagingException(String, Exception)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getCause()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getNextException()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setNextException(Exception)
M: 25 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
superToString()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toString()
M: 41 C: 10
20%
M: 7 C: 1
13%
M: 4 C: 1
20%
M: 11 C: 4
27%
M: 0 C: 1
100%

Coverage

1: /*
2: * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package jakarta.mail;
18:
19: /**
20: * The base class for all exceptions thrown by the Messaging classes
21: *
22: * @author John Mani
23: * @author Bill Shannon
24: */
25: public class MessagingException extends Exception {
26:
27: /**
28: * The next exception in the chain.
29: *
30: * @serial
31: */
32: private Exception next;
33:
34: private static final long serialVersionUID = -7569192289819959253L;
35:
36: /**
37: * Constructs a MessagingException with no detail message.
38: */
39: public MessagingException() {
40:         super();
41:         initCause(null);        // prevent anyone else from setting it
42: }
43:
44: /**
45: * Constructs a MessagingException with the specified detail message.
46: *
47: * @param s                the detail message
48: */
49: public MessagingException(String s) {
50:         super(s);
51:         initCause(null);        // prevent anyone else from setting it
52: }
53:
54: /**
55: * Constructs a MessagingException with the specified
56: * Exception and detail message. The specified exception is chained
57: * to this exception.
58: *
59: * @param s                the detail message
60: * @param e                the embedded exception
61: * @see        #getNextException
62: * @see        #setNextException
63: * @see        #getCause
64: */
65: public MessagingException(String s, Exception e) {
66:         super(s);
67:         next = e;
68:         initCause(null);        // prevent anyone else from setting it
69: }
70:
71: /**
72: * Get the next exception chained to this one. If the
73: * next exception is a MessagingException, the chain
74: * may extend further.
75: *
76: * @return        next Exception, null if none.
77: */
78: public synchronized Exception getNextException() {
79:         return next;
80: }
81:
82: /**
83: * Overrides the <code>getCause</code> method of <code>Throwable</code>
84: * to return the next exception in the chain of nested exceptions.
85: *
86: * @return        next Exception, null if none.
87: */
88: @Override
89: public synchronized Throwable getCause() {
90:         return next;
91: }
92:
93: /**
94: * Add an exception to the end of the chain. If the end
95: * is <strong>not</strong> a MessagingException, this
96: * exception cannot be added to the end.
97: *
98: * @param        ex        the new end of the Exception chain
99: * @return                <code>true</code> if this Exception
100: *                        was added, <code>false</code> otherwise.
101: */
102: public synchronized boolean setNextException(Exception ex) {
103:         Exception theEnd = this;
104:•        while (theEnd instanceof MessagingException &&
105:          ((MessagingException)theEnd).next != null) {
106:          theEnd = ((MessagingException)theEnd).next;
107:         }
108:         // If the end is a MessagingException, we can add this
109:         // exception to the chain.
110:•        if (theEnd instanceof MessagingException) {
111:          ((MessagingException)theEnd).next = ex;
112:          return true;
113:         } else
114:          return false;
115: }
116:
117: /**
118: * Override toString method to provide information on
119: * nested exceptions.
120: */
121: @Override
122: public synchronized String toString() {
123:         String s = super.toString();
124:         Exception n = next;
125:•        if (n == null)
126:          return s;
127:•        StringBuilder sb = new StringBuilder(s == null ? "" : s);
128:•        while (n != null) {
129:          sb.append(";\n nested exception is:\n\t");
130:•         if (n instanceof MessagingException) {
131:                 MessagingException mex = (MessagingException)n;
132:                 sb.append(mex.superToString());
133:                 n = mex.next;
134:          } else {
135:                 sb.append(n.toString());
136:                 n = null;
137:          }
138:         }
139:         return sb.toString();
140: }
141:
142: /**
143: * Return the "toString" information for this exception,
144: * without any information on nested exceptions.
145: */
146: private final String superToString() {
147:         return super.toString();
148: }
149: }