Class ExceptionUtils

java.lang.Object
com.bonitasoft.processbuilder.extension.ExceptionUtils

public class ExceptionUtils extends Object
A utility class for handling logging and exception throwing. This class centralizes error management to ensure consistency.
  • Method Details

    • logAndThrow

      public static <T extends Exception> void logAndThrow(Supplier<T> exceptionSupplier, String format, Object... args) throws T
      Logs a formatted error message and then throws a new instance of a specified exception. This method is a safe and generic way to handle exceptions by using a Supplier, which avoids the complexities and potential runtime errors of Reflection. It leverages the logging framework's ability to format messages, which is more efficient because the message is only constructed if the log level is active.
      Type Parameters:
      T - The type of the exception to be thrown. This must be a subclass of Exception.
      Parameters:
      exceptionSupplier - A Supplier that provides an instance of the exception to be thrown. The supplier's get() method should create and return a new exception instance, typically via a lambda or a constructor reference (e.g., IllegalArgumentException::new).
      format - A parameterized message format string compatible with the logging framework's formatters (e.g., using `{}`). This format string will be logged to the error level.
      args - A variable-length argument list of objects to be substituted into the format string. These objects correspond to the `{}` placeholders in the format string.
      Throws:
      T - The exception instance provided by the exceptionSupplier.