Explain or provide an example showing how each of the following Exceptions could arise. a) ArithmeticException b) NullPointerException c) NumberFormatException d) IndexOutOfBoundsException
Explain or provide an example showing how each of the following Exceptions could arise.
a) ArithmeticException
b) NullPointerException
c) NumberFormatException
d) IndexOutOfBoundsException
Answer:a) An arithmetic operation could not take place because of an illegal action such as division by zero or square root of a negative number
b) An object was not instantiated (it had the value null) before a message was passed to it
c) An expected value for a numeric operation was not a legal number, such as trying to parse a String value to create an equivalent int where the String contains a non-digit character
d) A numeric parameter used as an index into an object such as an array, String or Vector was out of range, such as charAt(-1)
Comments
Post a Comment