code: public static void exceptionToControlChannel(
                                  Throwable e,
                                  String msg,
                                  BasicServerControlChannel control) {
          // how to convert exception stack trace to string?
          // i am sure it can be done easier.
          java.io.StringWriter writer = new java.io.StringWriter();
          e.printStackTrace(new java.io.PrintWriter(writer));
          String stack = writer.toString();
  
          // 451 Requested action aborted: local error in processing.
          LocalReply reply = new LocalReply(451, msg + "\n" +
                                            e.toString() + "\n" +
                                            stack);
          control.write(reply);
  
      }
docs: Convert the exception to a negative 451 reply, and pipe
  it to the provided control channel.