SlideShare ist ein Scribd-Unternehmen logo
1 von 27
IADCS Diploma Course Exception Handling U Nyein Oo COO/Director(IT) Myanma Computer Co., Ltd
Introduction to Exception  ,[object Object],[object Object],[object Object],[object Object]
Purpose of Exception handling ,[object Object],[object Object],[object Object]
Handling Exceptions  ,[object Object],[object Object],[object Object],[object Object]
Structure of Exception Object Error Throwable Exception (LinkageError, ThreadDeath, VirtualMachineError) ClassNotFoundException IOException(EOF,FileNotFound) NoSuchFieldException NoSuchMethodException RuntimeException (Arithemetic,IllegalArgument, IndexOutOfBounds,NullPointer)
Structure of Exception(Cont:) Object Throwable Error Exception Runtime Exception uncheck check uncheck
How exception work? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exception handling Model ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Structure of the exception handling model  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Advantages of ‘Catch and Throw’ Model   ,[object Object],[object Object]
‘ try’ and ‘catch’ Blocks   ,[object Object],[object Object],[object Object],[object Object],[object Object]
try’ and ‘catch’ Blocks (Contd…) ,[object Object],[object Object],[object Object],[object Object]
Example of catch and throw model //Number Format Exception Example class Try_Example{ public static void main(String args[]){ try{ int n=Integer.parseInt(args[0]); System.out.println("N is "+n); } catch(Exception e){ System.out.println("E is "+e); } } }
Example(cont) //Arithemetic Exception Example class Try_Example{ public static void main(String args[]){ int demo=0; try{ System.out.println(20/demo); } catch(Exception e){ System.out.println("E is "+e); } } }
Multiple Catch Blocks   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Multiple Catch Blocks  (Contd…) ,[object Object],[object Object],[object Object],[object Object]
‘finally’ Block ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
‘ finally’ Block (Contd…) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
‘ finally’ Block (Contd…) ,[object Object],[object Object],[object Object]
Example of Finally Block //Finally Block Example class Finally_Example{ public static void main(String args[]){ int demo=0; try{ System.out.println(20/demo); } catch(Exception e){ System.out.println("E is "+e); } finally{ System.out.println("Finally Executed"); } } }
User-defined Exceptions with ‘throw’ and ‘throws’ statements   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
User-defined Exceptions with ‘throw’ and ‘throws’ statements (Contd…) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
User-defined Exceptions with ‘throw’ and ‘throws’ statements (Contd…) ,[object Object],[object Object]
User Defined Exception Example public class ExTest{ public static void main(String args[]){ int num=Integer.parseInt(args[0]); try{ if(num<0) throw new MyExceptionTest(); } catch(MyExceptionTest e) { System.out.println(e); } } } public class MyExceptionTest extends ArithmeticException{ MyExceptionTest(){ super(&quot;You have passed Illegal Operation&quot;); } }
Multi catch example public class Pre { public static void main (String argv[]) { try { double d = Double.valueOf(argv[0]).doubleValue();   System.out.println (d); } catch (ArrayIndexOutOfBoundsException e) { System.out.println (&quot;An argument is required.&quot;); return; } catch (NumberFormatException e) { System.out.println (&quot;The argument must be a real number.&quot;); return; } } }
List of Exceptions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Thank You!

Weitere ähnliche Inhalte

Was ist angesagt?

Java exception handling
Java exception handlingJava exception handling
Java exception handling
BHUVIJAYAVELU
 
Exception handling
Exception handlingException handling
Exception handling
Iblesoft
 

Was ist angesagt? (20)

Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception Handling
 
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
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
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-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 Python
Exception handling in PythonException handling in Python
Exception handling in Python
 
Exception handling
Exception handlingException handling
Exception handling
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling ppt
 
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 loops
Java loopsJava loops
Java loops
 
Exception handling in c++
Exception handling in c++Exception handling in c++
Exception handling in c++
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Exception handling
Exception handlingException handling
Exception handling
 

Ähnlich wie Exception Handling

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
rohitgudasi18
 
9781439035665 ppt ch11
9781439035665 ppt ch119781439035665 ppt ch11
9781439035665 ppt ch11
Terry Yoast
 

Ähnlich wie Exception Handling (20)

Java unit3
Java unit3Java unit3
Java unit3
 
Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threads
 
Z blue exception
Z blue   exceptionZ blue   exception
Z blue exception
 
1.12 Exception Handing.pptx
1.12 Exception Handing.pptx1.12 Exception Handing.pptx
1.12 Exception Handing.pptx
 
Exception handling
Exception handlingException handling
Exception handling
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
 
17 exceptions
17   exceptions17   exceptions
17 exceptions
 
Interface andexceptions
Interface andexceptionsInterface andexceptions
Interface andexceptions
 
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
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
java exception.pptx
java exception.pptxjava exception.pptx
java exception.pptx
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exception handling in java.pptx
Exception handling in java.pptxException handling in java.pptx
Exception handling in java.pptx
 
Chap12
Chap12Chap12
Chap12
 
Exception handling
Exception handlingException handling
Exception handling
 
9781439035665 ppt ch11
9781439035665 ppt ch119781439035665 ppt ch11
9781439035665 ppt ch11
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception Handling In Java Presentation. 2024
Exception Handling In Java Presentation. 2024Exception Handling In Java Presentation. 2024
Exception Handling In Java Presentation. 2024
 
Java-Exception Handling Presentation. 2024
Java-Exception Handling Presentation. 2024Java-Exception Handling Presentation. 2024
Java-Exception Handling Presentation. 2024
 
12. Exception Handling
12. Exception Handling 12. Exception Handling
12. Exception Handling
 

Mehr von backdoor

Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
backdoor
 
Distributed Programming using RMI
 Distributed Programming using RMI Distributed Programming using RMI
Distributed Programming using RMI
backdoor
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet
backdoor
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMI
backdoor
 
Client Side Programming with Applet
Client Side Programming with AppletClient Side Programming with Applet
Client Side Programming with Applet
backdoor
 
Java Network Programming
Java Network ProgrammingJava Network Programming
Java Network Programming
backdoor
 
Windows Programming with Swing
Windows Programming with SwingWindows Programming with Swing
Windows Programming with Swing
backdoor
 
Windows Programming with AWT
Windows Programming with AWTWindows Programming with AWT
Windows Programming with AWT
backdoor
 
Multithreading
MultithreadingMultithreading
Multithreading
backdoor
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
backdoor
 
IO and serialization
IO and serializationIO and serialization
IO and serialization
backdoor
 
Java Intro
Java IntroJava Intro
Java Intro
backdoor
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
backdoor
 
AWT Program output
AWT Program outputAWT Program output
AWT Program output
backdoor
 
Data Security
Data SecurityData Security
Data Security
backdoor
 
Ne Course Part One
Ne Course Part OneNe Course Part One
Ne Course Part One
backdoor
 
Ne Course Part Two
Ne Course Part TwoNe Course Part Two
Ne Course Part Two
backdoor
 
Security Policy Checklist
Security Policy ChecklistSecurity Policy Checklist
Security Policy Checklist
backdoor
 

Mehr von backdoor (20)

Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
 
Distributed Programming using RMI
 Distributed Programming using RMI Distributed Programming using RMI
Distributed Programming using RMI
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMI
 
Client Side Programming with Applet
Client Side Programming with AppletClient Side Programming with Applet
Client Side Programming with Applet
 
Java Network Programming
Java Network ProgrammingJava Network Programming
Java Network Programming
 
Windows Programming with Swing
Windows Programming with SwingWindows Programming with Swing
Windows Programming with Swing
 
Windows Programming with AWT
Windows Programming with AWTWindows Programming with AWT
Windows Programming with AWT
 
Multithreading
MultithreadingMultithreading
Multithreading
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
 
IO and serialization
IO and serializationIO and serialization
IO and serialization
 
Java Intro
Java IntroJava Intro
Java Intro
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
AWT Program output
AWT Program outputAWT Program output
AWT Program output
 
Net Man
Net ManNet Man
Net Man
 
Data Security
Data SecurityData Security
Data Security
 
Ne Course Part One
Ne Course Part OneNe Course Part One
Ne Course Part One
 
Ne Course Part Two
Ne Course Part TwoNe Course Part Two
Ne Course Part Two
 
Net Sec
Net SecNet Sec
Net Sec
 
Security Policy Checklist
Security Policy ChecklistSecurity Policy Checklist
Security Policy Checklist
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Exception Handling

  • 1. IADCS Diploma Course Exception Handling U Nyein Oo COO/Director(IT) Myanma Computer Co., Ltd
  • 2.
  • 3.
  • 4.
  • 5. Structure of Exception Object Error Throwable Exception (LinkageError, ThreadDeath, VirtualMachineError) ClassNotFoundException IOException(EOF,FileNotFound) NoSuchFieldException NoSuchMethodException RuntimeException (Arithemetic,IllegalArgument, IndexOutOfBounds,NullPointer)
  • 6. Structure of Exception(Cont:) Object Throwable Error Exception Runtime Exception uncheck check uncheck
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13. Example of catch and throw model //Number Format Exception Example class Try_Example{ public static void main(String args[]){ try{ int n=Integer.parseInt(args[0]); System.out.println(&quot;N is &quot;+n); } catch(Exception e){ System.out.println(&quot;E is &quot;+e); } } }
  • 14. Example(cont) //Arithemetic Exception Example class Try_Example{ public static void main(String args[]){ int demo=0; try{ System.out.println(20/demo); } catch(Exception e){ System.out.println(&quot;E is &quot;+e); } } }
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20. Example of Finally Block //Finally Block Example class Finally_Example{ public static void main(String args[]){ int demo=0; try{ System.out.println(20/demo); } catch(Exception e){ System.out.println(&quot;E is &quot;+e); } finally{ System.out.println(&quot;Finally Executed&quot;); } } }
  • 21.
  • 22.
  • 23.
  • 24. User Defined Exception Example public class ExTest{ public static void main(String args[]){ int num=Integer.parseInt(args[0]); try{ if(num<0) throw new MyExceptionTest(); } catch(MyExceptionTest e) { System.out.println(e); } } } public class MyExceptionTest extends ArithmeticException{ MyExceptionTest(){ super(&quot;You have passed Illegal Operation&quot;); } }
  • 25. Multi catch example public class Pre { public static void main (String argv[]) { try { double d = Double.valueOf(argv[0]).doubleValue(); System.out.println (d); } catch (ArrayIndexOutOfBoundsException e) { System.out.println (&quot;An argument is required.&quot;); return; } catch (NumberFormatException e) { System.out.println (&quot;The argument must be a real number.&quot;); return; } } }
  • 26.