Code example for StringWriter

Methods: toString

0
        String s = String.format(format, args);
        errPrintln(s);
    } 
 
    public void exception(Throwable t, String format, Object... args) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        t.printStackTrace(pw);
        pw.flush();
        error(format + "\n" + sw.toString(), args);
    } 
 
    /** for unit testing */ 
    protected void errPrintln(String msg) {
        System.err.println(msg);
    } 
 
    /** for unit testing */ 
    protected void outPrintln(String msg) {
        System.out.println(msg);
    }