SlideShare a Scribd company logo
Exceptions
What is Exception Handling?
• Exception is the one that stops the execution
of the program unexpectedly.
• The process of handling these exceptions is
called Exception Handling.
Exception Handling Mechanism
Exception can be handled in 3 ways:
• try block
• Catch block
• Finally block
Exception Classes
Throwable
Error
Exception
Runtime
Exceptions
Compile – enforced
Exception
Object
1
2
Try and Catch block
try
{
//code where you think exception would occur
}
catch(Exception_Class reference)
{
//Catch the exception and displays that exception
}
Try – Catch example
public class Try_Catch {
public static void main(String[] args) {
int y=0;
try {
System.out.println(5/y);
}
catch(Exception e) {
System.out.println(“Divide By Zero Exception”);
}
}
}
Multiple Catches
• When there is a chance
of getting different
types of exceptions we
use multiple catch
block for a try block.
try
{
//statements
}
catch(Exception_Class reference)
{
//statements for one type of exception
}
catch(Exception_Class reference)
{
//statements for other type of exception
}
Multiple- Catch Example
package com.edureka.exception.multiplecatch;
class Multiple_Catch {
int n;
int array[]=new int[3];
Multiple_Catch(int n)
{
try{
if(n==0)
System.out.println(5/n);
else{
array[3]=n;
System.out.println(array);
}
}
catch(ArrayIndexOutOfBoundsException
arrayexception)
{
System.out.println(arrayexception);
}
catch(ArithmeticException divideexception)
{
System.out.println(divideexception);
}
}
}
Multiple- Catch Example
package com.edureka.exception.multiplecatch;
class Main {
public static void main(String[] args)
{
Multiple_Catch multiplecatch1= new Multiple_Catch(0);
Multiple_Catch multiplecatch2= new Multiple_Catch(5);
}
}
What is throw keyword?
• throw is a keyword which is used to call the sub class of an
exception class.
• This keyword is also used to throw the exception occurred in try
block to catch block.
try{
throw new Exception_class(“message”);
}
catch(Exception_class reference){
//statements
}
Example using throw keyword
package com.edureka.exception.throwkeyword;
public class Student {
Student(int studentid, String name){
try{
if(studentid==0)
throw new Exception("id can not be zero");
else
System.out.println("The id of "+name+"
is:"+studentid);
}
catch (Exception e) {
System.out.println(e);
}
}
}
package com.edureka.exception.throwkeyword;
public class Main {
public static void main(String[] args) {
Student student1 = new Student(0,"STUDENT1");
Student student2 = new Student(1,"STUDENT2");
}
}
What is throws keyword?
• throws is a keyword applied to methods for
which an exception has raised during its
execution.
returntype method_name throws Exception_Class
{
// statements
}
Example using throws keyword
package com.edureka.throwskeyword;
public class GiveInput {
void takeInput() throws IOException
{
BufferedReader reader=new
BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter your name");
String name=reader.readLine();
System.out.println("Your name is: "+name);
}
}
package com.edureka.throwskeyword;
public class Main {
public static void main(String[] args) throws
IOException {
GiveInput input=new GiveInput();
input.takeInput();
}
}
Uses of finally keyword
• When we want a set of statements to be executed
even after an exception has occurred then we use
finally block.
• finally
{
//statements that needs to be executed after
exception
}
Types of Exception
• Run-time Exceptions.
• Compile Enforced Exception
Run-Time Exceptions
• Are also called as Unchecked Exception.
• These exceptions are handled at run-time i.e by JVM
after they have occurred by using try and catch
block.
• Eg: ArrayIndexOutOfBoundsException,
ArithmeticException
NullPointerException
Complier-enforced Exceptions
• Are also called as Checked Exceptions.
• These exceptions are handled by java complier
before they occur by using throws keyword.
• Eg: IOException,
FileNotFoundException
User-defined Exceptions
• Across built-in exceptions user can also
define his own exceptions.
• It can be done by defining a class that extends
Exception class and creating a constructor of
the class (user-defined) with string argument
to print that message when exception occurs.
Advantages of Exception
• The program will still execute even if an exception
arises i.e finally block.
• If you can't handle the exception JVM will handle the
exception if we use throws keyword.
• We can differentiate the exceptions that have
occurred.
Errors and Error Handling
 Design-time error: These are the errors that occur while
designing the programs.
Eg: Syntax errors
These errors will be shown with a red mark in eclipse IDE so
that you can easily find and correct it.
Errors and Error Handling
 Logical error: These are the errors done by programmer. The
programs with these errors will run but does not produce
desired results.
Eg: getting division of two numbers as output but expected is
multiplication of numbers.
These errors can be rectified by understanding the logic and
checking whether it is works out correctly or not.
•Q& A..?
Thanks..!

More Related Content

What's hot (19)

Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
priyankazope
 
Exception
ExceptionException
Exception
Navaneethan Naveen
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
Elizabeth alexander
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
ravinderkaur165
 
Exception handling in java
Exception handling in java Exception handling in java
Exception handling in java
yugandhar vadlamudi
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in Java
Vadym Lotar
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handling
raksharao
 
exception handling in java
exception handling in java exception handling in java
exception handling in java
aptechsravan
 
exception handling
exception handlingexception handling
exception handling
Manav Dharman
 
9781439035665 ppt ch11
9781439035665 ppt ch119781439035665 ppt ch11
9781439035665 ppt ch11
Terry Yoast
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
Abhishek Pachisia
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
pooja kumari
 
Chap12
Chap12Chap12
Chap12
Terry Yoast
 
Java
JavaJava
Java
SangeethaSasi1
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
Pratik Soares
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
ARAFAT ISLAM
 
Exception handling
Exception handlingException handling
Exception handling
Raja Sekhar
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
Lovely Professional University
 
Exception Handling
Exception HandlingException Handling
Exception Handling
backdoor
 

Viewers also liked (8)

Java class 8
Java class 8Java class 8
Java class 8
Edureka!
 
Java class 1
Java class 1Java class 1
Java class 1
Edureka!
 
Java class 4
Java class 4Java class 4
Java class 4
Edureka!
 
Java
Java Java
Java
Edureka!
 
Java class 5
Java class 5Java class 5
Java class 5
Edureka!
 
Java class 6
Java class 6Java class 6
Java class 6
Edureka!
 
Java class 3
Java class 3Java class 3
Java class 3
Edureka!
 
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
Edureka!
 
Java class 8
Java class 8Java class 8
Java class 8
Edureka!
 
Java class 1
Java class 1Java class 1
Java class 1
Edureka!
 
Java class 4
Java class 4Java class 4
Java class 4
Edureka!
 
Java class 5
Java class 5Java class 5
Java class 5
Edureka!
 
Java class 6
Java class 6Java class 6
Java class 6
Edureka!
 
Java class 3
Java class 3Java class 3
Java class 3
Edureka!
 
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
Edureka!
 

Similar to Java class 7 (20)

UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptx
RDeepa9
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptx
RDeepa9
 
Java-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handlingJava-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handling
raksharao
 
Exception Handling.pptx
Exception Handling.pptxException Handling.pptx
Exception Handling.pptx
primevideos176
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
Kavitha713564
 
Exception handling in java-PPT.pptx
Exception handling in java-PPT.pptxException handling in java-PPT.pptx
Exception handling in java-PPT.pptx
sonalipatil225940
 
L12.2 Exception handling.pdf
L12.2  Exception handling.pdfL12.2  Exception handling.pdf
L12.2 Exception handling.pdf
MaddalaSeshu
 
Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for all
HayomeTakele
 
Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
Rajkattamuri
 
unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025
AKSHAYBHABAD5
 
41c
41c41c
41c
Sireesh K
 
Multi catch statement
Multi catch statementMulti catch statement
Multi catch statement
myrajendra
 
Exception Handling,finally,catch,throw,throws,try.pptx
Exception Handling,finally,catch,throw,throws,try.pptxException Handling,finally,catch,throw,throws,try.pptx
Exception Handling,finally,catch,throw,throws,try.pptx
ArunPatrick2
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
lalithambiga kamaraj
 
Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threads
DevaKumari Vijay
 
Exception handling basic
Exception handling basicException handling basic
Exception handling basic
TharuniDiddekunta
 
UNIT 2 UNIT 3 OBJECT ORIENTED PROGRAMMING
UNIT 2 UNIT 3 OBJECT ORIENTED PROGRAMMINGUNIT 2 UNIT 3 OBJECT ORIENTED PROGRAMMING
UNIT 2 UNIT 3 OBJECT ORIENTED PROGRAMMING
thirunavukkarasu57
 
exception handling in java.ppt
exception handling in java.pptexception handling in java.ppt
exception handling in java.ppt
Varshini62
 
Pi j4.2 software-reliability
Pi j4.2 software-reliabilityPi j4.2 software-reliability
Pi j4.2 software-reliability
mcollison
 
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
Exception Handling Multithreading: Fundamental of Exception; Exception types;...Exception Handling Multithreading: Fundamental of Exception; Exception types;...
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
poongothai11
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptx
RDeepa9
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptx
RDeepa9
 
Java-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handlingJava-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handling
raksharao
 
Exception Handling.pptx
Exception Handling.pptxException Handling.pptx
Exception Handling.pptx
primevideos176
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
Kavitha713564
 
Exception handling in java-PPT.pptx
Exception handling in java-PPT.pptxException handling in java-PPT.pptx
Exception handling in java-PPT.pptx
sonalipatil225940
 
L12.2 Exception handling.pdf
L12.2  Exception handling.pdfL12.2  Exception handling.pdf
L12.2 Exception handling.pdf
MaddalaSeshu
 
Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for all
HayomeTakele
 
Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
Rajkattamuri
 
unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025unit 4 msbte syallbus for sem 4 2024-2025
unit 4 msbte syallbus for sem 4 2024-2025
AKSHAYBHABAD5
 
Multi catch statement
Multi catch statementMulti catch statement
Multi catch statement
myrajendra
 
Exception Handling,finally,catch,throw,throws,try.pptx
Exception Handling,finally,catch,throw,throws,try.pptxException Handling,finally,catch,throw,throws,try.pptx
Exception Handling,finally,catch,throw,throws,try.pptx
ArunPatrick2
 
Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threads
DevaKumari Vijay
 
UNIT 2 UNIT 3 OBJECT ORIENTED PROGRAMMING
UNIT 2 UNIT 3 OBJECT ORIENTED PROGRAMMINGUNIT 2 UNIT 3 OBJECT ORIENTED PROGRAMMING
UNIT 2 UNIT 3 OBJECT ORIENTED PROGRAMMING
thirunavukkarasu57
 
exception handling in java.ppt
exception handling in java.pptexception handling in java.ppt
exception handling in java.ppt
Varshini62
 
Pi j4.2 software-reliability
Pi j4.2 software-reliabilityPi j4.2 software-reliability
Pi j4.2 software-reliability
mcollison
 
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
Exception Handling Multithreading: Fundamental of Exception; Exception types;...Exception Handling Multithreading: Fundamental of Exception; Exception types;...
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
poongothai11
 

More from Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
Edureka!
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
Edureka!
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
Edureka!
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
Edureka!
 
What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
Edureka!
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
Edureka!
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
Edureka!
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
Edureka!
 

Recently uploaded (20)

IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
Sritoma Majumder
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
How to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guidesHow to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guides
Celine George
 
How to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 WebsiteHow to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 Website
Celine George
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
muneebrana3215
 
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
Julián Jesús Pérez Fernández
 
Critical Thinking and Bias with Jibi Moses
Critical Thinking and Bias with Jibi MosesCritical Thinking and Bias with Jibi Moses
Critical Thinking and Bias with Jibi Moses
Excellence Foundation for South Sudan
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based EducatorDiana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda
 
Order Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptxOrder Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptx
Arshad Shaikh
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar SirPHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
Diwakar Kashyap
 
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSELET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
OlgaLeonorTorresSnch
 
Exploring Identity Through Colombian Companies
Exploring Identity Through Colombian CompaniesExploring Identity Through Colombian Companies
Exploring Identity Through Colombian Companies
OlgaLeonorTorresSnch
 
Dashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo SlidesDashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo Slides
Celine George
 
LDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-inLDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-in
LDM & Mia eStudios
 
Introduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdfIntroduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdf
CME4Life
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
CBSE - Grade 11 - Mathematics - Ch 2 - Relations And Functions - Notes (PDF F...
Sritoma Majumder
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
How to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guidesHow to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guides
Celine George
 
How to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 WebsiteHow to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 Website
Celine George
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
muneebrana3215
 
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based EducatorDiana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda
 
Order Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptxOrder Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptx
Arshad Shaikh
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar SirPHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
Diwakar Kashyap
 
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSELET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
OlgaLeonorTorresSnch
 
Exploring Identity Through Colombian Companies
Exploring Identity Through Colombian CompaniesExploring Identity Through Colombian Companies
Exploring Identity Through Colombian Companies
OlgaLeonorTorresSnch
 
Dashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo SlidesDashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo Slides
Celine George
 
LDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-inLDMMIA Bonus GUEST GRAD Student Check-in
LDMMIA Bonus GUEST GRAD Student Check-in
LDM & Mia eStudios
 
Introduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdfIntroduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdf
CME4Life
 

Java class 7

  • 2. What is Exception Handling? • Exception is the one that stops the execution of the program unexpectedly. • The process of handling these exceptions is called Exception Handling.
  • 3. Exception Handling Mechanism Exception can be handled in 3 ways: • try block • Catch block • Finally block
  • 5. Try and Catch block try { //code where you think exception would occur } catch(Exception_Class reference) { //Catch the exception and displays that exception }
  • 6. Try – Catch example public class Try_Catch { public static void main(String[] args) { int y=0; try { System.out.println(5/y); } catch(Exception e) { System.out.println(“Divide By Zero Exception”); } } }
  • 7. Multiple Catches • When there is a chance of getting different types of exceptions we use multiple catch block for a try block. try { //statements } catch(Exception_Class reference) { //statements for one type of exception } catch(Exception_Class reference) { //statements for other type of exception }
  • 8. Multiple- Catch Example package com.edureka.exception.multiplecatch; class Multiple_Catch { int n; int array[]=new int[3]; Multiple_Catch(int n) { try{ if(n==0) System.out.println(5/n); else{ array[3]=n; System.out.println(array); } } catch(ArrayIndexOutOfBoundsException arrayexception) { System.out.println(arrayexception); } catch(ArithmeticException divideexception) { System.out.println(divideexception); } } }
  • 9. Multiple- Catch Example package com.edureka.exception.multiplecatch; class Main { public static void main(String[] args) { Multiple_Catch multiplecatch1= new Multiple_Catch(0); Multiple_Catch multiplecatch2= new Multiple_Catch(5); } }
  • 10. What is throw keyword? • throw is a keyword which is used to call the sub class of an exception class. • This keyword is also used to throw the exception occurred in try block to catch block. try{ throw new Exception_class(“message”); } catch(Exception_class reference){ //statements }
  • 11. Example using throw keyword package com.edureka.exception.throwkeyword; public class Student { Student(int studentid, String name){ try{ if(studentid==0) throw new Exception("id can not be zero"); else System.out.println("The id of "+name+" is:"+studentid); } catch (Exception e) { System.out.println(e); } } } package com.edureka.exception.throwkeyword; public class Main { public static void main(String[] args) { Student student1 = new Student(0,"STUDENT1"); Student student2 = new Student(1,"STUDENT2"); } }
  • 12. What is throws keyword? • throws is a keyword applied to methods for which an exception has raised during its execution. returntype method_name throws Exception_Class { // statements }
  • 13. Example using throws keyword package com.edureka.throwskeyword; public class GiveInput { void takeInput() throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter your name"); String name=reader.readLine(); System.out.println("Your name is: "+name); } } package com.edureka.throwskeyword; public class Main { public static void main(String[] args) throws IOException { GiveInput input=new GiveInput(); input.takeInput(); } }
  • 14. Uses of finally keyword • When we want a set of statements to be executed even after an exception has occurred then we use finally block. • finally { //statements that needs to be executed after exception }
  • 15. Types of Exception • Run-time Exceptions. • Compile Enforced Exception
  • 16. Run-Time Exceptions • Are also called as Unchecked Exception. • These exceptions are handled at run-time i.e by JVM after they have occurred by using try and catch block. • Eg: ArrayIndexOutOfBoundsException, ArithmeticException NullPointerException
  • 17. Complier-enforced Exceptions • Are also called as Checked Exceptions. • These exceptions are handled by java complier before they occur by using throws keyword. • Eg: IOException, FileNotFoundException
  • 18. User-defined Exceptions • Across built-in exceptions user can also define his own exceptions. • It can be done by defining a class that extends Exception class and creating a constructor of the class (user-defined) with string argument to print that message when exception occurs.
  • 19. Advantages of Exception • The program will still execute even if an exception arises i.e finally block. • If you can't handle the exception JVM will handle the exception if we use throws keyword. • We can differentiate the exceptions that have occurred.
  • 20. Errors and Error Handling  Design-time error: These are the errors that occur while designing the programs. Eg: Syntax errors These errors will be shown with a red mark in eclipse IDE so that you can easily find and correct it.
  • 21. Errors and Error Handling  Logical error: These are the errors done by programmer. The programs with these errors will run but does not produce desired results. Eg: getting division of two numbers as output but expected is multiplication of numbers. These errors can be rectified by understanding the logic and checking whether it is works out correctly or not.