try
{
//logic
}
catch(Exception e)
{
e.printStackTrace();
}
the printStackTrace() method will give us lines of statements related to exception but in which all lines are not useful for us
how we can restrict lines of exception details
You can write the stacktrace into a PrintWriter, then take the output of the writer, and restrict the number of bytes, or lines, or filter it with a regular expression, or whatever fits your needs.
} catch (Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
String fullStackTrace = sw.toString();
String restrictedStackTrace = ... //now you can manipulate the fullStackTrace
System.err.print(restrictedStackTrace);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With