Here you can find the source of toIOException(Throwable inThrownException, boolean inCheckCauses)
public static IOException toIOException(Throwable inThrownException, boolean inCheckCauses)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.util.HashSet; import java.util.Set; public class Main { public static IOException toIOException(Throwable inThrownException, boolean inCheckCauses) { if (inThrownException == null) { return null; }//from w ww . ja v a2 s .c o m if (inThrownException instanceof IOException) { return (IOException) inThrownException; } if (inCheckCauses) { final IOException ioe = findException(IOException.class, inThrownException); if (ioe != null) { return ioe; } } return new IOException(inThrownException); } @SuppressWarnings("unchecked") private static <T extends Throwable> T findException(Class<T> inThrowableClassToFind, Throwable inThrowable) { if (inThrowable == null || inThrowableClassToFind == null) { return null; } final Set<Throwable> checkedThrowables = new HashSet<>(); while (inThrowable != null) { if (inThrowableClassToFind.isAssignableFrom(inThrowable.getClass())) { return (T) inThrowable; } if (checkedThrowables.contains(inThrowable)) { return null; } checkedThrowables.add(inThrowable); inThrowable = inThrowable.getCause(); } return null; } }