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.InvalidParameterExceptionis already a subclass ofIllegalArgumentExceptiondesigned for use by the JCA/JCE engine classes (JavaDoc) and I wouldn’t use or subclass it in a different context.