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

Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 

Dernier (20)

Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 

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.