Java Dump Exception dumpException(String fileName, Throwable t)

Here you can find the source of dumpException(String fileName, Throwable t)

Description

Method dumpException.

License

Open Source License

Parameter

Parameter Description
fileName a parameter
t a parameter

Declaration

public static void dumpException(String fileName, Throwable t) 

Method Source Code


//package com.java2s;

import java.io.FileWriter;

import java.io.PrintWriter;

import java.io.StringWriter;
import java.io.Writer;

public class Main {
    /**//from  w w w.  j  a v a 2  s  . com
     * Method dumpException.
     * 
     * @param fileName
     * @param t
     */
    public static void dumpException(String fileName, Throwable t) {
        dumpException(fileName, t, false);
    }

    /**
     * Method dumpException.
     * 
     * @param fileName
     * @param t
     * @param appendFlag
     */
    public static void dumpException(String fileName, Throwable t, boolean appendFlag) {
        try {
            StringWriter sw = new StringWriter();
            t.printStackTrace(new PrintWriter(sw));
            Writer fileWriter = new FileWriter(fileName, appendFlag);
            fileWriter.write(sw.toString());
            fileWriter.close();
            fileWriter = null;
        } catch (Throwable t2) {
            t2.printStackTrace();
        }
    }
}

Related

  1. dumpException(Throwable e)
  2. dumpException(Throwable ex)