Checked equivalent to IllegalArgumentException?

Posted by jv1975oid on Stack Overflow See other posts from Stack Overflow or by jv1975oid
Published on 2010-03-18T16:32:24Z Indexed on 2010/03/18 16:41 UTC
Read the original article Hit count: 294

I have a method that takes an enum as a parameter and returns some information dependent on that parameter. However, that enum contains some values which should not be handled, and should raise an error condition. Currently the method throws an IllegalArgumentException but I would like this to be a checked exception to force callers to catch it (and return gracefully, logging an error). Is there something suitable or should I create my own Exception subclass?

I'm open to other patterns as well. A reasonable reaction would be that all values of the enum should be handled, but that isn't the case. When a new value is added to the enum, I want to make sure that this method does the right thing - alerting a human is preferable to using some default return value in this case.

Thanks for any advice.

© Stack Overflow or respective owner

Related posts about java

Related posts about exception-handling