M
Mark Space
Hi all,
Just curious: is there a better way to print a stack trace? I want to
be able to log them if I have to, so I'm converting the StacTrace to a
string. I wonder if there's a better/easier way to do this however.
Code fragments follow:
// Static method inside class IoUtil:
public static String StackTraceToString( Exception e )
{
ByteArrayOutputStream b = new ByteArrayOutputStream();
PrintStream p = new PrintStream( b );
e.printStackTrace( p );
p.flush();
return b.toString();
}
// Example use:
catch( IOException e )
{
System.err.println( "IO error while reading!" + e );
String st = IoUtil.StackTraceToString( e );
System.err.println( st );
this.log.fine( "IO error while reading!" );
this.log.fine( st );
}
The example use has an error with respect to non-static variables, but
ignore that and just focus on the stack trace part. Any comments much
appreciated.
Just curious: is there a better way to print a stack trace? I want to
be able to log them if I have to, so I'm converting the StacTrace to a
string. I wonder if there's a better/easier way to do this however.
Code fragments follow:
// Static method inside class IoUtil:
public static String StackTraceToString( Exception e )
{
ByteArrayOutputStream b = new ByteArrayOutputStream();
PrintStream p = new PrintStream( b );
e.printStackTrace( p );
p.flush();
return b.toString();
}
// Example use:
catch( IOException e )
{
System.err.println( "IO error while reading!" + e );
String st = IoUtil.StackTraceToString( e );
System.err.println( st );
this.log.fine( "IO error while reading!" );
this.log.fine( st );
}
The example use has an error with respect to non-static variables, but
ignore that and just focus on the stack trace part. Any comments much
appreciated.