SlideShare a Scribd company logo
EXCEPTION HANDLING
EXPLAINED BY HACKERS
PRESENTERS
• MUSKAN NAZEER
• AQSA ALTAF
• M. SHAHID
• M. WASEEM AKRAM
• M. AHMAD
• TALHA SHABBIR
AGENDA.
• What is Exception
• What is Exception Handling
• Exception Hierarchy in java
• Difference between Exception & Error.
• Types of Exception
• Types of Built-in- Exception
• Create and Handle Exception..
Exception
Exception Hierarchy
Exception Types.
Checked Exception
Unchecked Exception
Create & handle Exception
What is Exception
“An exception is an unexpected event, which occurs during the execution of a program i.e., at run
time, that disrupts the normal flow of the program.”
What is Exception handling:
“The Exception Handling in Java is one of the powerful mechanisms to handle the exception. in
program. so that the normal flow of the program can be maintained.”
Purpose:
The purpose of Exception handling is to detect and report an exception so that proper action can be
taken and prevent the program which is automatically terminate or stop the execution because of that
exception
Example:
Statement 1;
Statement 2;
Statement 3; (an exception occurs)
Statement 4;
Statement 5;
Suppose there are 5 Statements in a program and there occurs an exception at
Statement 3 the rest of the code of statement 3,4,5 will not be executed. If we
perform exception handling the rest of the statement will be executed.
If Exception occurs then we have two ways;
 pass the exception to its caller (using throws keyword)
 handle exception (using try, catch and finally keyword)
Keyword Used in Exception Handling are given:
Keywords Description
try
Java try block is used to enclose the code that might
throw an exception. The try block must be followed by
catch or finally.
catch
The "catch" block is used to handle the exception. It
must be followed by try block which means we can't
use catch block alone. catch block may be one or more
than one.
finally
The "finally" block is used to execute the necessary
code of the program. It is executed whether an
exception is handled or not.
Throws
The "throws" keyword is used to pass the exception to
its caller. It is always used with method signature.
Throw
“throw” keyword used to create user
define exception. it is used inside the method.
Exception Hierarchy in java
In the Java platform, many classes derive directly from Object, other classes derive from some of those
classes, and so on, forming a hierarchy of classes. Object is the parent class of all the classes in java.
Difference Between Exception and Error?
Exception Error
Exception occurs due to our Program. Error occurs due to lack of system resources.
Exception can be handled. Error cannot be handled.
Types:
Checked Exception
Unchecked Exception.
Type:
Unchecked Only.
Examples:
Null Pointer Exception, Array Index Out of Bounds
Exception, Class not Found Exception etc.
Examples:
Virtual Machine Error, Stack Over Flow Error,
Assertion Error, Linkage Error, Out of Memory Error,
etc..
Exception Types
Difference Between Built In exception and User Defined Exception?
Built In exception User Defined Exception
Built-in exceptions are the exceptions that are
already available in Java libraries.
Built-in exceptions are the exceptions that are not
available in Java libraries.
Predefined exceptions are raised implicitly
(Automatically) by the runtime system.
Predefined exception must be raised explicitly by
throw keyword.
Types:
Checked Exception
Unchecked exception
Types:
unchecked exception
Types of Built-in- Exception
 checked Exception:
 unchecked Exception.
Some exception are given:
 File Not Found Exception: This Exception is raised when a file is not accessible or does not exist.
 IO Exception: It is thrown when an input-output operation failed or interrupted
 NoSuchMethodException: It is thrown when accessing a method that is not found.
 Interrupted Exception: It is thrown when a thread is waiting, sleeping, or doing some processing, and it is
interrupted.
Checked Exception
“If compiler checks exception, then it is known as checked exception. These exceptions should be either
pass or handled during compile time. If we do not catch or handle them then the compiler will throw a
compilation error. These are the sub classes of the Exception class.”
FileNotFoundException:
Output:
Exception Handling
Output:
Unchecked Exception
If The compiler does not check exception it is known as unchecked exception. An unchecked exception (also
known as a runtime exception). Exceptions are checked at runtime.
Unchecked exceptions result from faulty logic that can occur anywhere in a software program. For example, if a
developer invokes a method on a null object, an unchecked NullPointerException occurs.
 Arithmetic Exception: It is thrown when an exceptional condition has occurred in an arithmetic operation.
 Array Index Out Of Bounds Exception: it occurs if we print out of bound array in program.
 Class Not Found Exception: it is occur if we delete the class of java file after comile.
 NoSuchMethodException: It is thrown when accessing a method that is not found.
 String Index out of Bounds Exception: It is thrown by String class methods to indicate that an index is either
negative or greater than the size of the string
Some exception are given:
ArithmeticException!
Handle Exception by Try Catch
EXCEPTION HANDLING in prograaming
Exception create ( by using throw keyword) Example
Output:
Exception Handling
output:
Execution
process
Catch block
Finally block
EXCEPTION HANDLING in prograaming

More Related Content

Similar to EXCEPTION HANDLING in prograaming (20)

PPTX
Exception Handling.pptx
primevideos176
 
PDF
Exception handling
Garuda Trainings
 
PDF
Exception handling
Garuda Trainings
 
PDF
Ch-1_5.pdf this is java tutorials for all
HayomeTakele
 
PPTX
Lec-01 Exception Handling in Java_javatpoint.pptx
MdNazmulHasanRuhan1
 
DOCX
VTU MCA 2022 JAVA Exceeption Handling.docx
Poornima E.G.
 
PPTX
Exception handling in Java
Ankit Rai
 
DOCX
Java Exception handling
Garuda Trainings
 
PPTX
UNIT III 2021R.pptx
RDeepa9
 
PPTX
UNIT III 2021R.pptx
RDeepa9
 
PPTX
Interface andexceptions
saman Iftikhar
 
PPT
Exceptionhandling
DrHemlathadhevi
 
PPTX
Chap2 exception handling
raksharao
 
PPTX
Java-Unit 3- Chap2 exception handling
raksharao
 
PDF
Java unit 11
Shipra Swati
 
PPTX
Exceptionhandling
Nuha Noor
 
PPT
Exception handling
Tata Consultancy Services
 
PPTX
Exception handling
Ardhendu Nandi
 
PPSX
Java Exceptions
jalinder123
 
PPSX
Java Exceptions Handling
DrRajeshreeKhande
 
Exception Handling.pptx
primevideos176
 
Exception handling
Garuda Trainings
 
Exception handling
Garuda Trainings
 
Ch-1_5.pdf this is java tutorials for all
HayomeTakele
 
Lec-01 Exception Handling in Java_javatpoint.pptx
MdNazmulHasanRuhan1
 
VTU MCA 2022 JAVA Exceeption Handling.docx
Poornima E.G.
 
Exception handling in Java
Ankit Rai
 
Java Exception handling
Garuda Trainings
 
UNIT III 2021R.pptx
RDeepa9
 
UNIT III 2021R.pptx
RDeepa9
 
Interface andexceptions
saman Iftikhar
 
Exceptionhandling
DrHemlathadhevi
 
Chap2 exception handling
raksharao
 
Java-Unit 3- Chap2 exception handling
raksharao
 
Java unit 11
Shipra Swati
 
Exceptionhandling
Nuha Noor
 
Exception handling
Tata Consultancy Services
 
Exception handling
Ardhendu Nandi
 
Java Exceptions
jalinder123
 
Java Exceptions Handling
DrRajeshreeKhande
 

Recently uploaded (20)

PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
Controller Request and Response in Odoo18
Celine George
 
Introduction to Indian Writing in English
Trushali Dodiya
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
Difference between write and update in odoo 18
Celine George
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
epi editorial commitee meeting presentation
MIPLM
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
infertility, types,causes, impact, and management
Ritu480198
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Ad

EXCEPTION HANDLING in prograaming

  • 2. PRESENTERS • MUSKAN NAZEER • AQSA ALTAF • M. SHAHID • M. WASEEM AKRAM • M. AHMAD • TALHA SHABBIR
  • 3. AGENDA. • What is Exception • What is Exception Handling • Exception Hierarchy in java • Difference between Exception & Error. • Types of Exception • Types of Built-in- Exception • Create and Handle Exception.. Exception Exception Hierarchy Exception Types. Checked Exception Unchecked Exception Create & handle Exception
  • 4. What is Exception “An exception is an unexpected event, which occurs during the execution of a program i.e., at run time, that disrupts the normal flow of the program.” What is Exception handling: “The Exception Handling in Java is one of the powerful mechanisms to handle the exception. in program. so that the normal flow of the program can be maintained.” Purpose: The purpose of Exception handling is to detect and report an exception so that proper action can be taken and prevent the program which is automatically terminate or stop the execution because of that exception
  • 5. Example: Statement 1; Statement 2; Statement 3; (an exception occurs) Statement 4; Statement 5; Suppose there are 5 Statements in a program and there occurs an exception at Statement 3 the rest of the code of statement 3,4,5 will not be executed. If we perform exception handling the rest of the statement will be executed. If Exception occurs then we have two ways;  pass the exception to its caller (using throws keyword)  handle exception (using try, catch and finally keyword)
  • 6. Keyword Used in Exception Handling are given: Keywords Description try Java try block is used to enclose the code that might throw an exception. The try block must be followed by catch or finally. catch The "catch" block is used to handle the exception. It must be followed by try block which means we can't use catch block alone. catch block may be one or more than one. finally The "finally" block is used to execute the necessary code of the program. It is executed whether an exception is handled or not. Throws The "throws" keyword is used to pass the exception to its caller. It is always used with method signature. Throw “throw” keyword used to create user define exception. it is used inside the method.
  • 7. Exception Hierarchy in java In the Java platform, many classes derive directly from Object, other classes derive from some of those classes, and so on, forming a hierarchy of classes. Object is the parent class of all the classes in java.
  • 8. Difference Between Exception and Error? Exception Error Exception occurs due to our Program. Error occurs due to lack of system resources. Exception can be handled. Error cannot be handled. Types: Checked Exception Unchecked Exception. Type: Unchecked Only. Examples: Null Pointer Exception, Array Index Out of Bounds Exception, Class not Found Exception etc. Examples: Virtual Machine Error, Stack Over Flow Error, Assertion Error, Linkage Error, Out of Memory Error, etc..
  • 10. Difference Between Built In exception and User Defined Exception? Built In exception User Defined Exception Built-in exceptions are the exceptions that are already available in Java libraries. Built-in exceptions are the exceptions that are not available in Java libraries. Predefined exceptions are raised implicitly (Automatically) by the runtime system. Predefined exception must be raised explicitly by throw keyword. Types: Checked Exception Unchecked exception Types: unchecked exception
  • 11. Types of Built-in- Exception  checked Exception:  unchecked Exception.
  • 12. Some exception are given:  File Not Found Exception: This Exception is raised when a file is not accessible or does not exist.  IO Exception: It is thrown when an input-output operation failed or interrupted  NoSuchMethodException: It is thrown when accessing a method that is not found.  Interrupted Exception: It is thrown when a thread is waiting, sleeping, or doing some processing, and it is interrupted. Checked Exception “If compiler checks exception, then it is known as checked exception. These exceptions should be either pass or handled during compile time. If we do not catch or handle them then the compiler will throw a compilation error. These are the sub classes of the Exception class.”
  • 15. Unchecked Exception If The compiler does not check exception it is known as unchecked exception. An unchecked exception (also known as a runtime exception). Exceptions are checked at runtime. Unchecked exceptions result from faulty logic that can occur anywhere in a software program. For example, if a developer invokes a method on a null object, an unchecked NullPointerException occurs.  Arithmetic Exception: It is thrown when an exceptional condition has occurred in an arithmetic operation.  Array Index Out Of Bounds Exception: it occurs if we print out of bound array in program.  Class Not Found Exception: it is occur if we delete the class of java file after comile.  NoSuchMethodException: It is thrown when accessing a method that is not found.  String Index out of Bounds Exception: It is thrown by String class methods to indicate that an index is either negative or greater than the size of the string Some exception are given:
  • 17. Handle Exception by Try Catch
  • 19. Exception create ( by using throw keyword) Example