Le 21/11/2009 07:48, Paulo Levi a écrit :
But i'm wondering why there isn't a global jvm system option for the new Thread(runnable).start() to perserve stack traces at least until the start method. Seems like a no brainer so that tools (like the netbeans debugger) can find where the misbehaving threads originate from, (instead of like now, where i have to depend on the names). Or am i missing something obvious?


You don't need the VM for that, something like that should work:

public class ThreadEx extends Thread {
  final Throwable where;
  {
    where = new Throwable();
    setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
      @Override
      public void uncaughtException(Thread t, Throwable e) {
        setLastCause(e, where);
        e.printStackTrace();
      }
    });
  }

  static void setLastCause(Throwable t, Throwable where) {
    for(;;) {
      Throwable cause = t.getCause();
      if (cause == null)
        break;
      t = cause;
    }
    t.initCause(where);
  }
}

Rémi

Reply via email to