catch( Exception e ){

   ByteArrayOutputStream newOut=new ByteArrayOutputStream();
   
   e.printStackTrace( new PrintStream( newOut ) );

   String exc=newOut.toString();
   
   System.out.println( "---\n"+exc+"\n---" );
}

Of course, you need to import java.io.*
or at least PrintStream and ByteArrayOutputStream

