code: private void writeNewException(Exception ex) throws IOException {
          output.writeByte(TC_EXCEPTION);
          resetSeenObjects();
          writeObjectInternal(ex, false, false, false); // No replacements
          resetSeenObjects();
      }
docs: Write exception {@code ex} into the receiver. It is assumed the
  exception has not been dumped yet. Returns
  the handle for this object (exception) which is dumped here.
  This is used to dump the exception instance that happened (if any) when
  dumping the original object graph. The set of seen objects will be reset
  just before and just after dumping this exception object.
  
  When exceptions are found normally in the object graph, they are dumped
  as a regular object, and not by this method. In that case, the set of
  "known objects" is not reset.
  
  @param ex
  Exception object to dump
  
  @throws IOException
  If an IO exception happened when writing the exception
  object.