You are on page 1of 2

EXPERIMENT NO 6

Exception Handling
Experiment Outcomes
M1.06 Construct programs by including an exception handling mechanism.

AIM:
A .Write a program to read two numbers and find answer for the equation (a x b) / (a - b) and
also create an array and print the element at the index which is user inputting. If any runtime
error occur it should be handled

ExceptionDemp

+main(String[] argos)

OBJECTIVES
To understand Exception handling in Java in java
THEORY
In Java, an exception is an event that disrupts the normal flow of the program. It is an object
which is thrown at runtime. Exception Handling is a mechanism to handle runtime errors such as
ClassNotFoundException, IOException, SQLException, RemoteException, etc.

Java provides five keywords that are used to handle the exception. The following table
describes each.

Keyw Description
ord

try The "try" keyword is used to specify a block where we should place an

exception code. It means we can't use try block alone. The try block must be

followed by either catch or finally.


catch The "catch" block is used to handle the exception. It must be preceded by try

block which means we can't use catch block alone. It can be followed by

finally block later.

finally The "finally" block is used to execute the necessary code of the program. It

is executed whether an exception is handled or not.

throw The "throw" keyword is used to throw an exception.

throws The "throws" keyword is used to declare exceptions. It specifies that there

may occur an exception in the method. It doesn't throw an exception. It is

always used with method signature.

PROCEDURE
Algorithm
1. Create a class with main() function.
2. Read a,b,index
3. Solve the equation (a+b /(a-b) if denominator become zero the goto step 5
4. Print the element at index if try to access element out of the array object or divide by zero
occur the goto step 5
5. Print “Error occurred”
6. Stop

Program

RESULT
Successfully implemented and executed program with static variable and methods

You might also like