Yes. (Because the string "34.56" can't be converted into
an int).
Exception
Here are two of the rules about how try/catch semantics try/catch blocks work:
- The first
catchblock to match the type ofExceptionthrown gets control.- The most specific
Exceptiontypes should appear first in the structure, followed by the more generalExceptiontypes.To make full sense of these rules you need to know more about
Exceptiontypes. Inspect the above hierarchy diagram ofException.An
ArithmeticExceptionis thrown for some types of arithmetic problems, such as when a division by integer zero is attempted. (However, not all arithmetic problems cause anArithmeticException.)Potential Gotcha!
floating point zero does not cause an ArithmeticException.
Floating point arithmetic does not throw exceptions.
In arranging the try blocks, a child class should
appear before any of its ancestors.
If class A is not an ancestor or descendant of class B,
then it doesn't matter which appears first.
You have a try block that might throw an ArithmeticException or some type of
RunTimeException .
Put these exceptions in the correct order in the catch blocks:
try
{
// statements which might throw an ArithmeticException
// or some type of RunTimeException
}
catch ( ex )
{
// statements to handle this
// type of exception
}
catch ( ex )
{
// statements to handle this
// type of exception
}
// Statements following the structure