throw with String

David Holmes David.Holmes at
Thu Sep 16 02:09:50 PDT 2010

Ralf Ebert said the following on 09/16/10 18:25:
>> Isn't this a java.lang.Error:
>> "An Error is a subclass of Throwable that indicates serious problems
>> that a reasonable application should not try to catch."
> imho "serious" means "JVM almost dying", I was thinking more about
> casual, unserious errors like:
> throw new RuntimeException("You can specify a width in pixel OR in
> percent, but not both!");

IllegalArgumentException. This should be part of the API contract. 
(Though it sounds to me like a design issue with the API.)

> throw new RuntimeException("setFoo() requires bar.");

IllegalStateException. Again part of contract.

> throw new RuntimeException("Value cannot be set because of null value in
> nested property 'foo'!");

Either of the above depending on context but again part of the API contract.

Use the right exception to do the job IMHO.

David Holmes

> (these are cases from a library I'm writing where I'm very sure than an
> application developer is misusing the library when trying to catch one
> of these exceptions specifically)
> Ralf

More information about the coin-dev mailing list