The answer is yes. The below code is proving it. You can use it as written here or as you wrote it. Both should pass the if
statement.
import java.sql.SQLException;
import javax.resource.ResourceException;
public class Linking {
public static void main(String[] args) {
SQLException resW = new SQLException("blubb");
ResourceException resX = new ResourceException("a message", resW);
SQLException sqlExc = null;
Throwable linkedExc = resX.getCause();
// if linkedExc exception is a SQL Exception, assign it to sqlExc
if (linkedExc instanceof SQLException) {
sqlExc = (SQLException) linkedExc;
}
if (sqlExc != null)
sqlExc.printStackTrace();
}
}
The documentation on ResourceException ( http://docs.oracle.com/javaee/1.4/api/javax/resource/ResourceException.html#setLinkedException%28java.lang.Exception%29 ) says:
Deprecated. J2SE release 1.4 supports a chained exception facility that allows any throwable to know about another throwable, if any, that caused it to get thrown. Refer to getCause and initCause methods of the java.lang.Throwable class.