Groovy web console

subscribe to the feed Subscribe
to this
site

Stack Trace to String

Published 3 weeks ago by Patricio Ascencio
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
def stackTraceToString(e) {
    java.io.StringWriter sw = new java.io.StringWriter();
    java.io.PrintWriter pw = new java.io.PrintWriter(sw);
    e.printStackTrace(pw);
    sw.toString();
}

def log(type,message){
    println("[${type}]: ${message}")
}

try {
  throw new RuntimeException("Error de prueba");
} catch(Exception e){
  log "Error", "Delete:" + stackTraceToString(e)
}