java - What exception to throw when pre-requisite method was not called? -
i have method getuser
retrieves user database. method demands verify user exists (via userexists(string username)
method.
if getuser
method invoked , user not exist, want throw unchecked exception, exception appropriate here? thought illegalargumentexception
, doesn't feel right, inputs may okay in cases, not others - not strictly "illegal". suggestions?
to me illegalargumentexception means argument illegal , illegal. th exception use illegalstateexception state of object check user not valid.
however may have exception specific enough create own.
public class usernamenotcheckedexception extends illegalstateexception { public usernamenotcheckedexception(string message) { super(message); } }
this may make debugging things easier.
a numberformatexception
subclass of illegalargumentexception
. ifyou try parse number 12qw4
give numberformatexception
, there nothing can make valid argument later. i.e. has nothing state of anything.
the javadoc illegalstateexception
states.
signals method has been invoked @ illegal or inappropriate time. in other words, java environment or java application not in appropriate state requested operation.
Comments
Post a Comment