Skip to content

Commit

Permalink
Add sneakyThrow method to OfficeStamperException class
Browse files Browse the repository at this point in the history
This method encapsulates and throws provided exceptions as an OfficeStamperException. It improves error handling by standardizing the way unexpected errors are thrown and logged. This addition also enhances code readability and maintainability.
  • Loading branch information
caring-coder committed Sep 17, 2024
1 parent c24e085 commit 7550ae5
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

/**
* OfficeStamperException is a subclass of RuntimeException that represents an exception that can be thrown during the
* processing of an Office document using the OfficeStamper library
* .
* processing of an Office document using the OfficeStamper library.
* It provides additional constructors to handle different scenarios.
*/
public class OfficeStamperException
Expand Down Expand Up @@ -51,4 +50,15 @@ public OfficeStamperException(String message, Throwable cause) {
public OfficeStamperException() {
super("Unexpected exception");
}

/**
* Throws an OfficeStamperException encapsulating the provided exception.
*
* @param exception the exception to be thrown
* @return this method does not return a value; it always throws an exception
* @throws OfficeStamperException always thrown to indicate an unexpected error.
*/
public static <T> T sneakyThrow(Exception exception) {
throw new OfficeStamperException("Unexpected error", exception);
}
}

0 comments on commit 7550ae5

Please sign in to comment.