001/* 002 * Copyright 2002-2014 the original author or authors. 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 * https://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 017package org.springframework.core; 018 019import java.io.IOException; 020 021/** 022 * Subclass of {@link IOException} that properly handles a root cause, 023 * exposing the root cause just like NestedChecked/RuntimeException does. 024 * 025 * <p>Proper root cause handling has not been added to standard IOException before 026 * Java 6, which is why we need to do it ourselves for Java 5 compatibility purposes. 027 * 028 * <p>The similarity between this class and the NestedChecked/RuntimeException 029 * class is unavoidable, as this class needs to derive from IOException. 030 * 031 * @author Juergen Hoeller 032 * @since 2.0 033 * @see #getMessage 034 * @see #printStackTrace 035 * @see org.springframework.core.NestedCheckedException 036 * @see org.springframework.core.NestedRuntimeException 037 */ 038@SuppressWarnings("serial") 039public class NestedIOException extends IOException { 040 041 static { 042 // Eagerly load the NestedExceptionUtils class to avoid classloader deadlock 043 // issues on OSGi when calling getMessage(). Reported by Don Brown; SPR-5607. 044 NestedExceptionUtils.class.getName(); 045 } 046 047 048 /** 049 * Construct a {@code NestedIOException} with the specified detail message. 050 * @param msg the detail message 051 */ 052 public NestedIOException(String msg) { 053 super(msg); 054 } 055 056 /** 057 * Construct a {@code NestedIOException} with the specified detail message 058 * and nested exception. 059 * @param msg the detail message 060 * @param cause the nested exception 061 */ 062 public NestedIOException(String msg, Throwable cause) { 063 super(msg, cause); 064 } 065 066 067 /** 068 * Return the detail message, including the message from the nested exception 069 * if there is one. 070 */ 071 @Override 072 public String getMessage() { 073 return NestedExceptionUtils.buildMessage(super.getMessage(), getCause()); 074 } 075 076}