Professional Documents
Culture Documents
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
block which means we can't use catch block alone. It can be followed by
finally The "finally" block is used to execute the necessary code of the program. It
throws The "throws" keyword is used to declare exceptions. It specifies that there
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