Package dev.comfast.util
Class ErrorKit
java.lang.Object
dev.comfast.util.ErrorKit
ErrorKit is a set of useful functions for error handling.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Supplier<RuntimeException>Short supplier for RuntimeException, fits to Streams/Optionalsstatic <T> TSimilarly to lombokSneakyThrows, wraps any checked / unchecked Exception into RuntimeException
-
Constructor Details
-
ErrorKit
public ErrorKit()
-
-
Method Details
-
_fail
Short supplier for RuntimeException, fits to Streams/OptionalsUsage example:
found = someStream.findFirst().orElseThrow(_fail("Not found '%s'", someParam)) value = someOptional.orElseThrow(_fail("Oh no !"))- Parameters:
errorMsg- message if error happensmsgParams- format params for errorMsg- Returns:
- Supplier for RuntimeException, fits to Streams/Optionals
-
rethrow
Similarly to lombokSneakyThrows, wraps any checked / unchecked Exception into RuntimeExceptionAdds additional error message and original Exception as cause.
Usage example:rethrow(() -> somethingThrowsCheckedException(), "Something failed"); rethrow(() -> somethingCanFail(), "Something failed, see: '%s'", "some param");- Type Parameters:
T- function return type- Parameters:
getter- wrapped functionerrorMsg- message if error happenmsgParams- format params for errorMsg- Returns:
- function result
-