Possible Exceptions
The code in the try{} block
might throw
(1) an IOException,
(2) a NumberFormatException,
or
(3) an ArithmeticException.
try
{
System.out.println("Enter the numerator:");
inData = stdin.readLine();
num = Integer.parseInt( inData );
System.out.println("Enter the divisor:");
inData = stdin.readLine();
div = Integer.parseInt( inData );
System.out.println( num + " / " + div + " is " + (num/div) );
}
An IOException might occur in either readLine() statement.
There is no try{} block for this type of exception,
so the method has to say throws IOException.
A NumberFormatException might occur if the user types in
"Rats" or other characters that can't be converted to an int.
There is a try{} block for this type of exception,
An ArithmeticException might occur if the user enters
data that can't be used in an integer division.
There is a try{} block for this type of exception,
|