Groovy web console

subscribe to the feed Subscribe
to this
site
Search for Wrapped Exception (via #groovywebconsole)
tweet this snippet Tweet
this
script

Search for Wrapped Exception

Published 3 months ago by Luis G. Epifanio with tags Search for Wrapped Exception
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import java.net.SocketTimeoutException
import java.util.concurrent.TimeoutException

Exception current = null

20.times{
    if(! current ){
        current = new SocketTimeoutException("Read timed out [$it]") // Cambiar tipo ac?para caso false
        println ">> ${current.cause == current}"
    }else{
        current = new Exception("Wrapped at [$it]", current )
    }
}

boolean isTimeout(final Exception exc ){
    Exception ref = exc
    List<Exception> list = []
    list << ref
    while ( /* list.size() < 25 && */  ref != null ){
        if(ref != ref.cause){ // Evita ciclos
            ref = ref.cause
            list << ref
        }else{
            break;
        }
    }
    list.any{ Exception e ->
        [TimeoutException, SocketTimeoutException].any { 
            it.isAssignableFrom(e.getClass())
        }
    }
}

println isTimeout(current)