Why limit this to IllegalArgument? Why not make it more generic? For instance, in ExceptionUtils:

public static <T extends Throwable> T format(final Function<? super String, ? extends T> factory, final String format, final Object... args) {
    return factory.apply(String.format(format, args));
}

public static <T extends Throwable> T format(final BiFunction<? super String, ? super Throwable, ? extends T> factory, final Throwable t, final String format, final Object... args) {
    return factory.apply(String.format(format, args), t);
}

These can then be called using ExceptionUtils.format(IllegalArgumentException::new, "message: %s", message) or ExceptionUtils.format(IllegalArgumentException::new, cause, "message: %s", message).

It's a bit verbose though, but it gives a lot more flexibility.


On 03/09/2019 19:04, Gary Gregory wrote:
Please read the source.

On Tue, Sep 3, 2019, 12:27 Xeno Amess <xenoam...@gmail.com> wrote:

Why don't you use java.lang.IllegalArgumentException instead?
And, why we need such a class, but not using
java.lang.IllegalArgumentException there?

Gary Gregory <garydgreg...@gmail.com> 于2019年9月3日周二 下午11:18写道:

Hi All:

I propose we take

https://commons.apache.org/proper/commons-text/xref/org/apache/commons/text/lookup/IllegalArgumentExceptions.html#IllegalArgumentExceptions
and make it a public class in [lang]. FWIW, I use a class like this in
many
projects at work.

Gary

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to