synchronized void handleDisconnectedException() {
    EventQueue queue = vm.eventQueue();
    while (connected) {
      try {
        EventSet eventSet = queue.remove();
        EventIterator iter = eventSet.eventIterator();
        while (iter.hasNext()) {
          Event event = iter.nextEvent();
          if (event instanceof VMDeathEvent) {
            vmDeathEvent((VMDeathEvent)event);
          } else if (event instanceof VMDisconnectEvent) {
            vmDisconnectEvent((VMDisconnectEvent)event);
          } 
        }
        eventSet.resume(); // Resume the VM
      } catch (InterruptedException exc) {
        // ignore
      }
    }
  }