Java Reference
In-Depth Information
public static void main(String[] args)
{
Scanner keyboardArg = new Scanner(System.in);
int number = getInt(keyboardArg);
System.out.println("You entered " + number);
}
}
3 . Try block entered.
Over 30.
After catch block
4. The output would then be
Try block entered.
Under 30.
After catch block
5. There are two throw statements:
throw new Exception("Over 30.");
throw new Exception("Under 30.");
6. When a throw statement is executed, it is the end of the enclosing try block. No
other statements in the try block are executed, and control passes to the following
catch block(s). When we say that control passes to the following catch block, we
mean that the exception object that is thrown is plugged in for the catch block
parameter and the code in the catch block is executed.
7 . try
{
System.out.println("Try block entered.");
if (waitTime > 30)
throw new Exception("Over 30.");
else if (waitTime < 30)
throw new Exception("Under 30.");
else
System.out.println("No exception.");
System.out.println("Leaving try block.");
}
8 . catch (Exception thrownObject)
{
System.out.println(thrownObject.getMessage());
}
9 . thrownObject
10. Yes, it is legal.
11. Yes, it is legal.
12. public class PowerFailureException extends Exception
Search WWH ::




Custom Search