You are on page 1of 17

SANJIVANI RURAL EDUCATION SOCIETY’S

SANJIVANI K.B.P POLYTECHINC, KOPARGOAN


(2023-2024)

A PROJECT REPORT ON

“EXCEPTION HANDLING ”
SUBJECT: JAVA PROGRAMMING [22412]

SUBMITTED BY:

Mst. Sushant Dushing [53]

Mst. Omkar Dube [50]

Guided by: Mr.K.P.JADHAV

DEPARTMENT OF COMPUTER TECHNOLOGY,


SANJIVANI K.B.P POLYTECHNIC, KOPARGOAN
(2023-24)
Sanjivani Rural Education Society’s
SANJIVANI K.B.P POLYTECHINC, KOPARGOAN

CERTIFICATE
This is a certified project report entitled

“EXCEPTION HANDLING”
SUBMITTED BY:

Mst. Sushant Dushing [53]

Mst. Omkar Dube [50]

Under our supervision and guidance for partial fulfillment of the of requirement for
Diploma in computer technology affiliated to
Maharashtra State Board of Technical Education, Mumbai
For Academidic year
2023-2024

Mr. K.P.JADHAV Mr. G.N. JORVEKAR


Project Guide HOD
ACKNOWLEDGEMENT
First and the foremost we, express me deep sense of gratitude, sincere thanks and deep
sense of appreciation to Project Guide Prof. K. P. Jadhav , Department of Computer
Technology, Sanjivani K.B.P. Polytechnic, Kopargaon. Your availability at any time
throughou th year,valuabl guidance ,opinion,view,comments,critics,encouragement,
and support tremendously boosted this project work.
Lots of thanks to Head, Computer Technology Department, Mr. G. N. Jorvekar for
providing me the best support we ever had. We like to express my sincere gratitude to
Prof. A.R. Mirikar Principal, Sanjivani K. B. P. Polytechnic, kopargaon for providing
a great platform to complete the project within the scheduled time.
We are also thankful to all the faculty member, Computer Technology Department,
Sanjivani K. B. P. Polytechnic, Kopargaon for giving comments for improvement of
work, encouragement and help during completion of the Project.
Last but not the least; we should say thanks from my bottom of heart to my family and
friend for their never ending love, help, and support in so many ways through all this
time.
Thank you so much

Diploma in Computer Technology,


Sanjivani K.B.P Polytechnic
Micro-Project Proposal
Title:

1.0 Aim/Benefits of the Micro-Project:

The aim of this course is to help the student to attain the following industry identified
competency through various teaching learning experiences:

Develop Applications using Java.Course Outcomes Addressed:

2.0 Course Outcome:

a. Develop programs using Object Oriented methodology in Java.


b. Apply concept of inheritance for code reusability.
c. Develop programs using multithreading.
d. Implement Exception Handling.
e. Develop programs using graphics and applet.
f. Develop programs for handling I/O and file streams.

3.0 Proposed Methodology:


• Discussion about the topic guide and among the group members.
• Literature survey.
• Submission of project proposal.
• Information collection.
• Analysis of data.
• Compilation of content.
• Representation.
• Editing and revising the content.
• Report preparation.

4
lOMoARcPSD|34300270

INDEX
Sr.no Title Page No.

1 Introduction 5

2 Algorithm for simple try-catch 6

3 Algorithm for try-catch block 6

4 Algorithm for throw and throws 7

5 Flowchart for simple try-catch and 8


final
6 Flowchart for try-catch block 9

7 Flowchart for throw and throws 10

8 Program for Exception handling 11 to 14

9 Output 15

10 Conclusion And References 16


lOMoARcPSD|34300270

INTRODUCTION

The Exception Handling in Java is one of the powerful mechanism to handle the
runtime errors so that the normal flow of the application can be maintained.

In this tutorial, we will learn about Java exceptions, it's types, and the difference between
checked and unchecked exceptions.

What is Exception in Java?


Dictionary Meaning: Exception is an abnormal condition.

In Java, an exception is an event that disrupts the normal flow of the program. It is an
object which is thrown at runtime.
The core advantage of exception handling is to maintain the normal flow of the
application. An exception normally disrupts the normal flow of the application;
that is why we need to handle exceptions.

Suppose there are 10 statements in a Java program and an exception occurs at


statement 5; the rest of the code will not be executed, i.e., statements 6 to 10 will
not be executed. However, when we perform exception handling, the rest of the
statements will be executed. That is why we use exception handling in Java.
lOMoARcPSD|34300270

Algorithm for simple try catch:


Step1:Start
Step2:Declare variables I and j
Step3:Initalise I and j by taking input from user
Step4:Divide I and j If exception then catch block
will get executed

Else
Display division of I and j
Step5:finally block will get executed
Step6:Stop

Algorithm for try catch block:


Step1:Start
Step2:declare array
Step3;declare variables index ,number and div
Step4:perform division of index , number and store it in div
If Exception then
Any of catch block will get executed according to exception
Else
Display division
Step5:finally block will get executed
Step6:stop.
lOMoARcPSD|34300270

Algorithm for throw and throws:


Step1:start
Step2:show method throws ArithmeticException
Step3:declare variable age
Step4:take input from user
Step5:if age<18 throw Arithmeticexception
Display not allowed to drive car
Else
Display you are allowed to drive car
Step6:stop
lOMoARcPSD|34300270

• Flowchart for simple try,catch and final


lOMoARcPSD|34300270

Flowcart for throw and throws:


lOMoARcPSD|34300270

Flowchart for try-catch block:


lOMoARcPSD|34300270

PROGRAM FOR EXCEPTION HANDLING


import java.util.Scanner;

class divide_by_zero { void


setdata() {

Scanner sc = new Scanner(System.in);


System.out.println("enter the value of i="); int i =
sc.nextInt();

System.out.println("enter the value of j="); int j


= sc.nextInt(); try { double div = i / j;

System.out.println("division of two number is=" + div);


}
catch (Exception e) {
System.out.println("##############################
ERROR OCCURED ########################");
System.out.println(e);
System.out.println(" PLEASE ENTER A VALID NUMBER");
}
finally {

System.out.println("program ended");
}
}}
lOMoARcPSD|34300270

class throw_throws {

// throw and throws void show() throws


ArithmeticException {

Scanner m = new Scanner(System.in);


System.out.println("enter the age of person=");

Int age = m.nextInt(); if (age < 18) {

throw new ArithmeticException("not allowed to drive car ");


} else {
System.out.println("you are allowed to drive car");
}
}
}

class exception_java { public static void


main(String[] args) {

divide_by_zero d = new divide_by_zero(); d.setdata();

// try catch block


lOMoARcPSD|34300270

int[] number1 = new int[4];


number1[0] = 23; number1[1]= 24;
number1[2] = 45; number1[3] =
45;

Scanner s = new Scanner(System.in);


System.out.println("enter the array index"); int ind
= s.nextInt();

System.out.println("enter the number you want to divide with index="); int


number = s.nextInt();

try {
double div=number1[ind] / number;
System.out.println("the value of array index entered is=" + number1[ind]);
System.out.println("the value of array-index/number is=" +div );
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println("ArrayIndexOutOfBoundsException occured");
System.out.println(e);

}
catch (ArithmeticException e) {
System.out.println("ArithmeticException occurerd");
System.out.println(e);

}
lOMoARcPSD|34300270

catch (Exception e) {
System.out.println(e);
} finally
{

System.out.println("CLASS ENDED SUCCESSFULLY");


}

// throw and throws


throw_throws t = new throw_throws();
t.show();

}
}
lOMoARcPSD|34300270

OUTPUT=>
lOMoARcPSD|34300270

Conclusion

In this project we learn to implement exception handling using


try-catch ,try- catch block, by using throw and throws keyword
and finally we learn about many exception such as:
1.ArrayIndexOutOfBoundException
2.ArithmeticException
3.NullPointerException etc.
By using throw key we can create out own exception and throws
indicates us that in specific method a specific Exception can occur.
By using try-catch we can avoid the unexpected conditions or
Exception and it helps to run program without any disturbance.
By using finally keyword
even if there is exception in program the also the finally statement
will get executed.

References

• https://www.geeksforgeeks.org/

• https://www.javatpoint.com/

• Various open source materials from Internet.

• Training notes.

• Discussion among the group and with guide.

• Some requirements are gathered through various books from


library.

You might also like