Class ExceptionUtils
java.lang.Object
com.bonitasoft.processbuilder.extension.ExceptionUtils
A utility class for handling logging and exception throwing.
This class centralizes error management to ensure consistency.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Exception>
voidlogAndThrow
(Supplier<T> exceptionSupplier, String format, Object... args) Logs a formatted error message and then throws a new instance of a specified exception.
-
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 aSupplier
, 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 ofException
.- Parameters:
exceptionSupplier
- ASupplier
that provides an instance of the exception to be thrown. The supplier'sget()
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 theformat
string.- Throws:
T
- The exception instance provided by theexceptionSupplier
.
-