What exception is thrown when a property or an available method is temporarily unavailable (since it does not make sense in the current state of the object)?
The following is an example of an illustrative example, do not consider it too serious, try to consider the issue itself, if you receive it.
A fractionclass that has read and write properties numeratorand a denominatorread- quotientonly property. If denominatorit is not 0, then it quotientshould return numerator/ denominatorotherwise it should throw an exception saying that the property value is not defined / available for the current state of the object (please, t ArithmeticExceptionor DivideByZeroException, the question is not arithmetic, it is closer to the final car model).
Another example would be a class object that performs complex calculations in a parallel thread and provides the result as a field - it can throw an exception if the calculations are not completed yet.
I'm interested in answers for the Java and .NET platforms.
source
share