SlideShare une entreprise Scribd logo
1  sur  13
Exceptions  Mr.PrasadSawantDepartment Of Computer ScienceProf .Ramkurshana More Arts, Commerce and Science College Akurdi. Mobile :9665755707 Email:sawanprasad@gmail.comBlog:http://prasadmsawant.blogspot.com/
Agenda 	 Define exception. Discuss what is meant by exception handing. Describe the try,catch and finally blocks. Examine multiple catch blocks. Explore nested try catch blocks. Explain  the use of throw and throws keywords. Create user defined exception.
What is exception? When an error is encountered during the execution of a program an exception  is said to have occurred.
Handling Exception … IF  B IS ZERO GO TO EROR C=A/B PRINT C GO TO EXIT  		ERROR: 		DISPLAY “CODE CAUSING ERROR DUE TO  DIVISION BY   	ZERO” EXIT: END BLOCK THAT HANDLES  ERROR
HANDLING EXCEPTION IN JAVA  OBJECT Error THROWABLE Exception SQLException AWT ERROR ClassNotFoundException Thread Death.. ……… ………
System-Defined Exception Raised implicitly by system because of illegal execution of program  When cannot continue program execution any more  Created by Java System automatically  Exception extended from Error class and RuntimeException class  ,[object Object],[object Object]
Programmer-Defined Exception  Exceptions raised by programmer  Check by compiler whether the exception handler for exception occurred exists or not If there is no handler, it is error  Sub class of Exception class
The exception handling model try  {  	// code  which is expected to throw an exception  } Catch (exception e1) { 	/* 	If exception is thrown in the try block ,is of type e1,then perform necessary action here  	*/ }
Multiple catch block Class catch22 {    public static void main(String  args[])    { 	 try       { 		String  num=args[0]; intnumValue=Interger.parseInt(num); System.out.println(“The squre is ”+numValue*numvalue”);        } 	 catch(ArrayIndexOutOfBoundException  e1) 	{ System.out.println(“No argument is given!”); 	} 	catch(NumberFormatException  e2)	       {  System.out.println(“Not  a number “);       }      } } C:>javac catch22       No argument is given! C:>javac catch22 a Not  a number C:>javac  catch22 3 The squre is 9
Nested try-catch  … try { int num=args.length;   try    { intnumValue=Integer.parseInt(args[0]); System.out.println(“The squre is “+numValue*numValue);   }    catch(NumberFormatExcption e1)   { System.out.println(“Not a Number!”);   } } catch (ArrayIndexOutOfBoundException e2) { System.out.println(“No arguments given!”); } …. C:>javac catch        No argument is given! C:>javac catch22 a Not  a number C:>javac  catch22 3 The squre is 9
Finally block The ‘finally ’block is guaranteed  to run  whether or not an exception occurs. The finally clauses of a try catch block will always execute ,even  if there are  return statement in the try catch part .  Try block No  exception Exception finally Catch  block finally
Using throws and throw Exception  are thrown with the help of the  ‘throw’ keyword  .The ‘throw’ keyword is used  to indicate that an exception has occurred .The operand of throw is an object of any class that is derived from the class ’Throwable’. The  throws keyword is used to list the exception that method can throw.
Exception handling in Java

Contenu connexe

Tendances (20)

Exception handling in java
Exception handling in java Exception handling in java
Exception handling in java
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Java exception
Java exception Java exception
Java exception
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Java: Exception
Java: ExceptionJava: Exception
Java: Exception
 
exception handling in java
exception handling in java exception handling in java
exception handling in java
 
7.error management and exception handling
7.error management and exception handling7.error management and exception handling
7.error management and exception handling
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
 
javaexceptions
javaexceptionsjavaexceptions
javaexceptions
 
Built in exceptions
Built in exceptions Built in exceptions
Built in exceptions
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handling
 
exception handling
exception handlingexception handling
exception handling
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exception handling
Exception handling Exception handling
Exception handling
 

Similaire à Exception handling in Java

Similaire à Exception handling in Java (20)

Exceptions
ExceptionsExceptions
Exceptions
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
 
java exception.pptx
java exception.pptxjava exception.pptx
java exception.pptx
 
JAVA PROGRAMMING- Exception handling - Multithreading
JAVA PROGRAMMING- Exception handling - MultithreadingJAVA PROGRAMMING- Exception handling - Multithreading
JAVA PROGRAMMING- Exception handling - Multithreading
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Exception handling in java.pptx
Exception handling in java.pptxException handling in java.pptx
Exception handling in java.pptx
 
1.12 Exception Handing.pptx
1.12 Exception Handing.pptx1.12 Exception Handing.pptx
1.12 Exception Handing.pptx
 
Unit II Java & J2EE regarding Java application development
Unit II Java & J2EE regarding Java application developmentUnit II Java & J2EE regarding Java application development
Unit II Java & J2EE regarding Java application development
 
Java-Exception Handling Presentation. 2024
Java-Exception Handling Presentation. 2024Java-Exception Handling Presentation. 2024
Java-Exception Handling Presentation. 2024
 
Exception Handling In Java Presentation. 2024
Exception Handling In Java Presentation. 2024Exception Handling In Java Presentation. 2024
Exception Handling In Java Presentation. 2024
 
Interface andexceptions
Interface andexceptionsInterface andexceptions
Interface andexceptions
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
17 exception handling - ii
17 exception handling - ii17 exception handling - ii
17 exception handling - ii
 
Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
 
Exception handling
Exception handlingException handling
Exception handling
 
Java Day-5
Java Day-5Java Day-5
Java Day-5
 
What is an exception in java?
What is an exception in java?What is an exception in java?
What is an exception in java?
 

Dernier

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 

Dernier (20)

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 

Exception handling in Java

  • 1. Exceptions Mr.PrasadSawantDepartment Of Computer ScienceProf .Ramkurshana More Arts, Commerce and Science College Akurdi. Mobile :9665755707 Email:sawanprasad@gmail.comBlog:http://prasadmsawant.blogspot.com/
  • 2. Agenda Define exception. Discuss what is meant by exception handing. Describe the try,catch and finally blocks. Examine multiple catch blocks. Explore nested try catch blocks. Explain the use of throw and throws keywords. Create user defined exception.
  • 3. What is exception? When an error is encountered during the execution of a program an exception is said to have occurred.
  • 4. Handling Exception … IF B IS ZERO GO TO EROR C=A/B PRINT C GO TO EXIT ERROR: DISPLAY “CODE CAUSING ERROR DUE TO DIVISION BY ZERO” EXIT: END BLOCK THAT HANDLES ERROR
  • 5. HANDLING EXCEPTION IN JAVA OBJECT Error THROWABLE Exception SQLException AWT ERROR ClassNotFoundException Thread Death.. ……… ………
  • 6.
  • 7. Programmer-Defined Exception Exceptions raised by programmer Check by compiler whether the exception handler for exception occurred exists or not If there is no handler, it is error Sub class of Exception class
  • 8. The exception handling model try { // code which is expected to throw an exception } Catch (exception e1) { /* If exception is thrown in the try block ,is of type e1,then perform necessary action here */ }
  • 9. Multiple catch block Class catch22 { public static void main(String args[]) { try { String num=args[0]; intnumValue=Interger.parseInt(num); System.out.println(“The squre is ”+numValue*numvalue”); } catch(ArrayIndexOutOfBoundException e1) { System.out.println(“No argument is given!”); } catch(NumberFormatException e2) { System.out.println(“Not a number “); } } } C:>javac catch22 No argument is given! C:>javac catch22 a Not a number C:>javac catch22 3 The squre is 9
  • 10. Nested try-catch … try { int num=args.length; try { intnumValue=Integer.parseInt(args[0]); System.out.println(“The squre is “+numValue*numValue); } catch(NumberFormatExcption e1) { System.out.println(“Not a Number!”); } } catch (ArrayIndexOutOfBoundException e2) { System.out.println(“No arguments given!”); } …. C:>javac catch No argument is given! C:>javac catch22 a Not a number C:>javac catch22 3 The squre is 9
  • 11. Finally block The ‘finally ’block is guaranteed to run whether or not an exception occurs. The finally clauses of a try catch block will always execute ,even if there are return statement in the try catch part . Try block No exception Exception finally Catch block finally
  • 12. Using throws and throw Exception are thrown with the help of the ‘throw’ keyword .The ‘throw’ keyword is used to indicate that an exception has occurred .The operand of throw is an object of any class that is derived from the class ’Throwable’. The throws keyword is used to list the exception that method can throw.