-
Feature Request
-
Resolution: Done
-
Minor
-
None
-
None
Sometimes you must use the same exception message for many different types of exception. It would be nice if you could give a parameter which can produce an exception, like this:
public interface MyLogs { // ... @Message(id = 1234, "The operation failed due to %s") <T extends Throwable> T operationFailed(@Producer Function<String, T> fn, String thing); }
And later at usage:
// ... throw MyLogs.log.operationFailed(IOException::new, "thingy");
A valid function parameter must return a type which is equal or assignable to the return type, and is assignable to Throwable. Other than that, it can be treated the same as as if you were dealing with a constructor class that has exactly one constructor, using the same matching/inference logic, meaning you could also accept BiFunction which accepts two arguments.