java.lang.Object
eu.cloudnetservice.driver.network.rpc.defaults.handler.util.ExceptionalResultUtil

public final class ExceptionalResultUtil extends Object
A utility class used to rethrow exceptions which happened during rpc on the executor side and got sent back to the original caller.
Since:
4.0
  • Constructor Details

    • ExceptionalResultUtil

      private ExceptionalResultUtil()
  • Method Details

    • serializeThrowable

      @NonNull public static @NonNull DataBuf serializeThrowable(@NonNull DataBuf.Mutable target, @NonNull @NonNull Throwable throwable)
      Serializes the given throwable into the given data buffer by writing the
      1. name of the exception which was thrown.
      2. optionally the message of the throwable if given.
      3. first stack trace element.
      Parameters:
      target - the buffer to serialize the exception to.
      throwable - the throwable to serialize into the buffer.
      Returns:
      the same buffer used to call the method, for chaining.
    • rethrowException

      public static void rethrowException(@NonNull @NonNull DataBuf source)
      Rethrows a serialized exception by wrapping the message and stack trace information into on message and using it as a message in a RPCExecutionException.
      Parameters:
      source - the source buffer to read the information from.
      Throws:
      RPCExecutionException - always, that is the point of this method.
    • serializeFirstElement

      @NonNull private static @NonNull DataBuf serializeFirstElement(@NonNull DataBuf.Mutable target, StackTraceElement @NonNull [] elements)
      Writes the first stack trace element into the given buffer using the following format:
      1. A boolean, indicating if a stack trace element is following, if false no other field will follow.
      2. A string, the class name where the exception happened.
      3. A string, the method name where the exception happened.
      4. An optional string, the file name where the exception happened.
      5. An integer, the line number where the exception happened.
      Parameters:
      target - the buffer to write the element to.
      elements - the stack trace elements.
      Returns:
      the same buffer used to call the methods, for chaining.