Page 124 - ComputerScience_Class_11
P. 124
7 {
8 result=a/b;
9 }
10 catch(ArithmeticException e)
11 {
12 System.out.println("You cannot divide anything by zero");
13 }
14 b=2;
15 System.out.println("After assigning 2 to b, we get");
16 result=a/b;
17 System.out.println("Answer: "+result);
18 }
19 }
The output of the preceding program is as follows:
BlueJ: Terminal Window - Java
Options
You cannot divide anything by zero
After assigning 2 to b, we get
Answer: 22
5.6.3 Input/Output Exceptions
Input/Output (I/O) exceptions are Java IOExceptions that occur whenever an input or output operation is unsuccessful.
For example, while trying to read data from a file that is not present, Java throws an I/O exception named
“FileNotFoundException”.
Some of the other exceptions are as follows:
• ArithmeticException: If there is any error in the arithmetic operation then this error is thrown.
• ArrayIndexOutOfBoundsException: It is thrown to indicate that an array has been accessed with an illegal index.
• ClassNotFoundException: When we try to access a class, which is not present then this error is thrown.
• NoSuchMethodException: When we try to access a method, which is not found then this error is thrown.
• NullPointerException: This exception is thrown when referring to the members of a null object. Null represents
nothing.
• InputMismatchException: This exception is thrown when we try to enter one type of data to another which is not
there.
#Interdisciplinary
Some More Programs
#Experiential Learning
Write a program to input the principal amount, rate of interest and time and then calculate
Program 1
the simple interest.
1 import java.util.*;
2 class simple_interest
122 Touchpad Computer Science (Ver. 3.0)-XI

