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

Popular posts from this blog

Discuss the seven characteristics of useful information.

Why have accounting software packages been designed with separate transaction modules?

A laboratory assistant prepared solution of 0.8 M, 0.6 M, 0.4 M, and 0.2 M sucrose, but forgot to label them. After realizing the error, the assistant randomly labeled the flasks containing these four unknown solutions as flask A, flask B, flask C, and flask D.