In Java when should you throw IllegalArgumentException
and when InvalidParameterException
? Coming from a C# background we would have an ArgumentNullException
that derived from ArgumentException
. If I would want to implement a equivalent ArgumentNullException
/ParameterNullException
in Java should I extend IllegalArgumentException
or InvalidParameterException
?
Note: I'm not trying to implement a ArgumentNullException
/ParameterNullException
this would just provide me with a better understanding if I could match up these with the C# framework.
There's no apparent need to subclass those exceptions, I'd use them right away to signal, that a method has been called with illegal arguments. I'd always describe the real cause in the exceptions message part.
java.security.InvalidParameterException
is already a subclass of IllegalArgumentException
designed for use by the JCA/JCE engine classes (JavaDoc) and I wouldn't use or subclass it in a different context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With