You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Gary Gregory <ga...@gmail.com> on 2018/01/12 17:30:10 UTC

[lang] new IllegalArgumentException shorcut.

Hi All:

We have code like:

throw new IllegalArgumentException(String.format("Minimum abbreviation
width is %d", minAbbrevWidth));

and I use this pattern a lot.

I would like to short cut this as follows:

throw IllegalArgumentExceptions.format("Minimum abbreviation width is %d",
minAbbrevWidth);

with a new factory class o.a.c.l.exceptions.IllegalArgumentExceptions

Thoughts?

Gary

Re: [lang] new IllegalArgumentException shorcut.

Posted by Gary Gregory <ga...@gmail.com>.
On Fri, Jan 12, 2018 at 10:45 AM, Pascal Schumacher <
pascalschumacher@gmx.net> wrote:

> Hi Gary,
>
> we already have Validate#isTrue(boolean expression, String message,
> Object... values), which throws an IllegalArgumentException when the
> expression is false.
>

Ah, but that is no good IMO since the exception is thrown INSIDE the isTrue
method which messes up code flow analysis and is harder to understand. It
also does not let you perform other operation after you know something is
wrong but before you throw the exception.

Gary


>
> Cheers,
> Pascal
>
>
> Am 12.01.2018 um 18:30 schrieb Gary Gregory:
>
>> Hi All:
>>
>> We have code like:
>>
>> throw new IllegalArgumentException(String.format("Minimum abbreviation
>> width is %d", minAbbrevWidth));
>>
>> and I use this pattern a lot.
>>
>> I would like to short cut this as follows:
>>
>> throw IllegalArgumentExceptions.format("Minimum abbreviation width is
>> %d",
>> minAbbrevWidth);
>>
>> with a new factory class o.a.c.l.exceptions.IllegalArgumentExceptions
>>
>> Thoughts?
>>
>> Gary
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: [lang] new IllegalArgumentException shorcut.

Posted by Pascal Schumacher <pa...@gmx.net>.
Hi Gary,

we already have Validate#isTrue(boolean expression, String message, 
Object... values), which throws an IllegalArgumentException when the 
expression is false.

Cheers,
Pascal

Am 12.01.2018 um 18:30 schrieb Gary Gregory:
> Hi All:
>
> We have code like:
>
> throw new IllegalArgumentException(String.format("Minimum abbreviation
> width is %d", minAbbrevWidth));
>
> and I use this pattern a lot.
>
> I would like to short cut this as follows:
>
> throw IllegalArgumentExceptions.format("Minimum abbreviation width is %d",
> minAbbrevWidth);
>
> with a new factory class o.a.c.l.exceptions.IllegalArgumentExceptions
>
> Thoughts?
>
> Gary
>


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