View Javadoc

1   /*
2    * Copyright 2002-2009 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.core;
18  
19  import java.io.IOException;
20  
21  /**
22   * Subclass of {@link IOException} that properly handles a root cause,
23   * exposing the root cause just like NestedChecked/RuntimeException does.
24   *
25   * <p>Proper root cause handling has not been added to standard IOException before
26   * Java 6, which is why we need to do it ourselves for Java 5 compatibility purposes.
27   *
28   * <p>The similarity between this class and the NestedChecked/RuntimeException
29   * class is unavoidable, as this class needs to derive from IOException.
30   *
31   * @author Juergen Hoeller
32   * @since 2.0
33   * @see #getMessage
34   * @see #printStackTrace
35   * @see org.springframework.core.NestedCheckedException
36   * @see org.springframework.core.NestedRuntimeException
37   */
38  public class NestedIOException extends IOException {
39  
40  	static {
41  		// Eagerly load the NestedExceptionUtils class to avoid classloader deadlock
42  		// issues on OSGi when calling getMessage(). Reported by Don Brown; SPR-5607.
43  		NestedExceptionUtils.class.getName();
44  	}
45  
46  
47  	/**
48  	 * Construct a <code>NestedIOException</code> with the specified detail message.
49  	 * @param msg the detail message
50  	 */
51  	public NestedIOException(String msg) {
52  		super(msg);
53  	}
54  
55  	/**
56  	 * Construct a <code>NestedIOException</code> with the specified detail message
57  	 * and nested exception.
58  	 * @param msg the detail message
59  	 * @param cause the nested exception
60  	 */
61  	public NestedIOException(String msg, Throwable cause) {
62  		super(msg);
63  		initCause(cause);
64  	}
65  
66  
67  	/**
68  	 * Return the detail message, including the message from the nested exception
69  	 * if there is one.
70  	 */
71  	@Override
72  	public String getMessage() {
73  		return NestedExceptionUtils.buildMessage(super.getMessage(), getCause());
74  	}
75  
76  }