Neat little function I made

Discussion in 'Plugin Development' started by Jacob Litewski, Jan 29, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Jacob Litewski

    I got tired of my plugin development (and horrid coding style :D) spewing stacktraces into the console, so I created this function to write the stacktraces into files and dump those into a stacktrace directory. IF it can't, it'll dump the exceptions into the console instead (the original exception and the exception on why it couldn't dump it into the file)

    This could theoretically make it easier to debug too, since you can upload the files to the forums in .txt documents.

    Enjoy!

    Code:
    public void dumpST(Exception e) {
            try {
                FileWriter fw = new FileWriter("dump.txt"); //I use a SimpleDateFormat to generate the filename
                BufferedWriter bw = new BufferedWriter(fw);
                StackTraceElement[] stack = e.getStackTrace();
                for(int i=0; i < (stack.length); i++)
                    { bw.write(stack[i].toString()); bw.newLine(); }
                bw.close();
                fw.close();
            } catch(Exception ex) {
                system.out.println("Unable to Dump Stacktrace into File! Dumping to Console Instead...");
                e.printStackTrace();
                ex.printStackTrace();
            }
        }
     
  2. Offline

    kneeven

    e.getLocalizedMessage() = <3
     
  3. Offline

    Jacob Litewski

    That is nice, but it wasn't enough information for me. I like having the actual stacktrace :p
     
Thread Status:
Not open for further replies.

Share This Page