Page 90 - CA_Blue( J )_Class10
P. 90
• Dividing a number by zero
int a, b, c;
a = 10;
b = 0;
c = a/b;
• Entering string value for a numeric variable
Enter your age: Seema
• Accessing a file that does not exist
If we take 0 in b, a runtime error will occur. Let us take an example.
Program 7 To check runtime errors.
1 class runtimeerror
2 {
3 public static void main()
4 {
5 int a=44,b=0,result;
6 result=a/b;
7 b=2;
8 result=a/b;
9 System.out.println("Answer : "+result);
10 }
11 }
When you run the preceding program, it will show the following error:
5.7 EXCEPTION
An exception is a problem that is caused by a runtime error that
occurred during the execution of a program. As soon as this Definition
type of error occurs, the program terminates abnormally and
displays a system-generated error message. Internally, the Java An exception is a situation in which the execution
interpreter creates an object of the Exception class and informs of a program stops abnormally.
the user that an error has occurred. Exception is the built-in
class of Java that is used to handle all types of exceptions. The
system-generated message is difficult for users to understand.
5.7.1 Types of Exception
There are two types of exceptions that occur in Java:
• Checked Exceptions: The exceptions that are checked at compile time. For example, exception related to input and
output, exception related to class not found, etc.
• Unchecked Exceptions: An exception that bypasses the compiler is known as an unchecked exception. It is also known as
a runtime exception. For example, if you divide a number by zero, then the divide by zero exception occurrs.
8888 Touchpad Computer Applications-X

