I am not as familiar with Java exception packages as I am with .NET. I am in a situation where, when programming in C #, I would throw a System.InvalidOperationException .
Before creating my own subclass of java.lang.RuntimeException I need to know if there is a similar type of exception that I should use in Java.
Exact scenario:
My class is a value object that provides an int intValue() method that returns an int. However, in some situations, the current value cannot be represented as int, so this class also provides boolean isInteger() so that API users can know when intValue() can be safely called.
If the caller calls intValue() when isInteger() is false , an exception should be thrown.
And the question is: what type of exception?
I know this question may not have the right answer, but given that I do not have much experience developing the Java API, I want to know from other Java developers what they would expect in this scenario.
thank
java design api exception-handling
Sergio Acosta Aug 01 2018-10-10T00: 00Z
source share