import sun.misc.ThrowableTraceListener; public class ThrowableTracer implements ThrowableTraceListener { int exceptions = 0; int errors = 0; public static void enable(ThrowableTracer t) { sun.misc.ThrowableTrace.setListener(t); } @Override public void traceThrowable(Throwable t) { synchronized (this) { if (t instanceof Error) { errors++; } else { exceptions++; } } } public int getExceptions() { return exceptions; } public int getErrors() { return errors; } }