@Override
    public void uncaughtException(Thread t, Throwable e) {
        if (!ready) {
            init();
        }

        Date date = new Date();

        try {
            FileWriter fstream = new FileWriter("debug.log", true);
            BufferedWriter out = new BufferedWriter(fstream);

            System.out.println(date.toString() + " Stack Trace:\n");

            out.write(date.toString() + " Stack Trace:");
            out.newLine();

            for (StackTraceElement ste : e.getStackTrace()) {
                System.out.println(ste + "\n");

                out.write(ste.toString());
                out.newLine();
            }
            
            out.close();
        } catch (Exception ex) {
        }

        terminate();
    }