]
James Perkins commented on LOGTOOL-124:
---------------------------------------
Good point. Annotation it is.
Ability to provide exception producer
-------------------------------------
Key: LOGTOOL-124
URL:
https://issues.jboss.org/browse/LOGTOOL-124
Project: Log Tool
Issue Type: Feature Request
Reporter: David Lloyd
Assignee: James Perkins
Priority: Minor
Fix For: 2.1.0.Alpha3
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:
{code}
public interface MyLogs {
// ...
@Message(id = 1234, "The operation failed due to %s")
<T extends Throwable> T operationFailed(@Producer Function<String, T> fn,
String thing);
}
{code}
And later at usage:
{code}
// ...
throw MyLogs.log.operationFailed(IOException::new, "thingy");
{code}
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.