Page 633 - Introduction to Programming with Java: A Problem Solving Approach
P. 633

                }
// end TestExceptions class
Review Question Solutions 599 //**********************************************************
public double eval(String n1, String n2)
throws IndexOutOfBoundsException
try
{
{
}
}
}
num = Integer.parseInt(n1) / Integer.parseInt(n2);
catch (NumberFormatException nfe)
{
num++;
System.out.println("in first catch");
catch (ArithmeticException ae)
{
}
num++;
System.out.println("in second catch");
return value[num];
//**********************************************************
public static void main(String[] args)
{
     Apago PDF Enhancer
TestExceptions te = new TestExceptions();
try
{
}
// end main
}
}
System.out.println(te.eval("5.0", "4"));
System.out.println(te.eval("5", "0"));
System.out.println(te.eval("22", "5"));
System.out.println(te.eval("33", "5"));
catch (Exception e)
{
System.out.println("in main's catch");
System.out.println("Bye");
Review Question Solutions
1. False. Many API method calls are safe, and there’s no need to put those method calls inside a try block.
2. True. You cannot put any statements between associated try and catch blocks.
3. True.
4. Put safe statements that use the results of dangerous operations inside the try block and after those dangerous operations.
 




















































   631   632   633   634   635