SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Types of Exceptions




      http://improvejava.blogspot.in/   1
Objectives

On completion of this period, you would be able to
 learn:
   • Exception hierarchy
   • Types of exceptions




                     http://improvejava.blogspot.in/   2
Recap

• In the last class, you have studied about the concept
  of multi-catch statements
• We have also written a sample program using multi
  catch statements
• A program on finally block was also examined




                    http://improvejava.blogspot.in/       3
Exception Hierarchy
      The following diagram shows exception hierarchy
                                 Throwable



                         Error                        Exception

Examples
(Out of memory error
Stack overflow errors)
                                                                   RuntimeException

                                                       Examples (ArithmeticException,
                                                       NullpointerException,
                 Fig. 46.1 Exception hierarchy         IndexOutofBoundsException)

                                                                                        4
                                 http://improvejava.blogspot.in/
Exception Hierarchy                      Contd ..

• All exception types are subclasses of the built-in
  class Throwable
• Throwable is at the top of the exception class
  hierarchy as shown in the Fig 46.1
• Below Throwable are two subclasses that
  partition exceptions into two distinct branches,
  namely
   • Exception
   • Error

                    http://improvejava.blogspot.in/              5
Exception Hierarchy                        Contd ..

• Exception class is used for exceptional conditions
  that user programs should catch
• It is used to create your own custom exception types
• RuntimeException is a subclass of Exception
• It is automatically defined for the programs that you
  write
• Includes things such as division by zero and invalid
  array indexing


                   http://improvejava.blogspot.in/              6
Error


• It defines exceptions that are not expected to be
  caught under normal circumstances by your
  program
• Stack overflow is an example of such an error




                  http://improvejava.blogspot.in/     7
Type of Exceptions
• There are two types of exceptions in Java
   • Unchecked exceptions
   • Checked exceptions




                    http://improvejava.blogspot.in/
                              9CM604.46               8
Unchecked Exceptions


• The compiler does not check to see if a method
  handles or throws these exceptions
   • Hence the name unchecked
• They need not be included in any method’s throws
  list




                  http://improvejava.blogspot.in/    9
Checked Exceptions

• The compiler checks whether these exceptions were
  handled in the method
• That must be included in a method’s throws list
• Compiler error occurs if these exceptions were not
  handled by the methods




                   http://improvejava.blogspot.in/     10
Unchecked Exceptions Examples




   Table 46.1 Unchecked Exception
         http://improvejava.blogspot.in/   11
Checked Exceptions Examples




  Table 46.2 Checked Exception
         http://improvejava.blogspot.in/   12
Summary
•   All exception types are subclasses of the built-in
    class Throwable
•   Throwable is at the top of the exception class
    hierarchy
•   Exception, Error are subclasses of Throwable
•   Types of exception
    • Unchecked exceptions
    • Checked exceptions



                     http://improvejava.blogspot.in/     13
Quiz
1. Which exceptions types are not expected to be
   caught under normal circumstances by your
   program

  A. Error
  B. Exceptions
  C. None




                  http://improvejava.blogspot.in/   14
Frequently Asked Questions

1. Explain about the various types of Exceptions
2. List out the various checked and unchecked
   exceptions




                  http://improvejava.blogspot.in/   15

Weitere ähnliche Inhalte

Was ist angesagt?

Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And MultithreadingShraddha
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javapooja kumari
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVASAGARDAVE29
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in JavaJava2Blog
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in JavaAnkit Rai
 
Java string handling
Java string handlingJava string handling
Java string handlingSalman Khan
 
Java exception handling
Java exception handlingJava exception handling
Java exception handlingBHUVIJAYAVELU
 
Java - Exception Handling Concepts
Java - Exception Handling ConceptsJava - Exception Handling Concepts
Java - Exception Handling ConceptsVicter Paul
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in javaNilesh Dalvi
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and OperatorsMarwa Ali Eissa
 

Was ist angesagt? (20)

Java threads
Java threadsJava threads
Java threads
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
Control statements in java programmng
Control statements in java programmngControl statements in java programmng
Control statements in java programmng
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
 
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
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
Java annotations
Java annotationsJava annotations
Java annotations
 
Core java
Core javaCore java
Core java
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Java IO
Java IOJava IO
Java IO
 
Creating your own exception
Creating your own exceptionCreating your own exception
Creating your own exception
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Java - Exception Handling Concepts
Java - Exception Handling ConceptsJava - Exception Handling Concepts
Java - Exception Handling Concepts
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
 
OOP java
OOP javaOOP java
OOP java
 
List in java
List in javaList in java
List in java
 

Andere mochten auch

Multi catch statement
Multi catch statementMulti catch statement
Multi catch statementmyrajendra
 
Eventos party mix
Eventos party mixEventos party mix
Eventos party mixholjer_123
 
Sonrrisa brillante estomatologia
Sonrrisa brillante estomatologiaSonrrisa brillante estomatologia
Sonrrisa brillante estomatologiallamoros
 
Campanha Marketing TV Tambaú 2013
Campanha Marketing TV Tambaú 2013Campanha Marketing TV Tambaú 2013
Campanha Marketing TV Tambaú 2013tvtambausbt
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47myrajendra
 
Eventos party mix[1]
Eventos party mix[1]Eventos party mix[1]
Eventos party mix[1]holjer_123
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handlingkamal kotecha
 

Andere mochten auch (8)

Multi catch statement
Multi catch statementMulti catch statement
Multi catch statement
 
Presentación2
Presentación2Presentación2
Presentación2
 
Eventos party mix
Eventos party mixEventos party mix
Eventos party mix
 
Sonrrisa brillante estomatologia
Sonrrisa brillante estomatologiaSonrrisa brillante estomatologia
Sonrrisa brillante estomatologia
 
Campanha Marketing TV Tambaú 2013
Campanha Marketing TV Tambaú 2013Campanha Marketing TV Tambaú 2013
Campanha Marketing TV Tambaú 2013
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47
 
Eventos party mix[1]
Eventos party mix[1]Eventos party mix[1]
Eventos party mix[1]
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 

Ähnlich wie Types of Exceptions Guide

Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception HandlingMaqdamYasir
 
Exception handling
Exception handlingException handling
Exception handlingMinal Maniar
 
Exception handling
Exception handlingException handling
Exception handlingpooja kumari
 
Exception handling in java-PPT.pptx
Exception handling in java-PPT.pptxException handling in java-PPT.pptx
Exception handling in java-PPT.pptxsonalipatil225940
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptxRDeepa9
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptxRDeepa9
 
Introduction to java exceptions
Introduction to java exceptionsIntroduction to java exceptions
Introduction to java exceptionsSujit Kumar
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handlingraksharao
 
Java-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handlingJava-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handlingraksharao
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javaAdil Mehmoood
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in JavaVadym Lotar
 
Exceptionhandling
ExceptionhandlingExceptionhandling
ExceptionhandlingNuha Noor
 
EXCEPTION HANDLING in prograaming
EXCEPTION HANDLING in prograamingEXCEPTION HANDLING in prograaming
EXCEPTION HANDLING in prograamingMuskanNazeer
 
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 allHayomeTakele
 
lecture-c-corr-effkkkkkkkkkkkkkp (1).ppt
lecture-c-corr-effkkkkkkkkkkkkkp (1).pptlecture-c-corr-effkkkkkkkkkkkkkp (1).ppt
lecture-c-corr-effkkkkkkkkkkkkkp (1).pptZeeshanAli593762
 

Ähnlich wie Types of Exceptions Guide (20)

Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception Handling
 
Exception handling
Exception handlingException handling
Exception handling
 
Javasession4
Javasession4Javasession4
Javasession4
 
16 exception handling - i
16 exception handling - i16 exception handling - i
16 exception handling - i
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception handling in java-PPT.pptx
Exception handling in java-PPT.pptxException handling in java-PPT.pptx
Exception handling in java-PPT.pptx
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptx
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptx
 
Introduction to java exceptions
Introduction to java exceptionsIntroduction to java exceptions
Introduction to java exceptions
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handling
 
Java-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handlingJava-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handling
 
Exception handling in .net
Exception handling in .netException handling in .net
Exception handling in .net
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in Java
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
EXCEPTION HANDLING in prograaming
EXCEPTION HANDLING in prograamingEXCEPTION HANDLING in prograaming
EXCEPTION HANDLING in prograaming
 
Exception handling in ASP .NET
Exception handling in ASP .NETException handling in ASP .NET
Exception handling in ASP .NET
 
Exception hierarchy
Exception hierarchyException hierarchy
Exception hierarchy
 
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
 
lecture-c-corr-effkkkkkkkkkkkkkp (1).ppt
lecture-c-corr-effkkkkkkkkkkkkkp (1).pptlecture-c-corr-effkkkkkkkkkkkkkp (1).ppt
lecture-c-corr-effkkkkkkkkkkkkkp (1).ppt
 

Mehr von myrajendra (20)

Fundamentals
FundamentalsFundamentals
Fundamentals
 
Data type
Data typeData type
Data type
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Dao example
Dao exampleDao example
Dao example
 
Sessionex1
Sessionex1Sessionex1
Sessionex1
 
Internal
InternalInternal
Internal
 
3. elements
3. elements3. elements
3. elements
 
2. attributes
2. attributes2. attributes
2. attributes
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to html
 
Headings
HeadingsHeadings
Headings
 
Forms
FormsForms
Forms
 
Css
CssCss
Css
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Starting jdbc
Starting jdbcStarting jdbc
Starting jdbc
 

Types of Exceptions Guide

  • 1. Types of Exceptions http://improvejava.blogspot.in/ 1
  • 2. Objectives On completion of this period, you would be able to learn: • Exception hierarchy • Types of exceptions http://improvejava.blogspot.in/ 2
  • 3. Recap • In the last class, you have studied about the concept of multi-catch statements • We have also written a sample program using multi catch statements • A program on finally block was also examined http://improvejava.blogspot.in/ 3
  • 4. Exception Hierarchy The following diagram shows exception hierarchy Throwable Error Exception Examples (Out of memory error Stack overflow errors) RuntimeException Examples (ArithmeticException, NullpointerException, Fig. 46.1 Exception hierarchy IndexOutofBoundsException) 4 http://improvejava.blogspot.in/
  • 5. Exception Hierarchy Contd .. • All exception types are subclasses of the built-in class Throwable • Throwable is at the top of the exception class hierarchy as shown in the Fig 46.1 • Below Throwable are two subclasses that partition exceptions into two distinct branches, namely • Exception • Error http://improvejava.blogspot.in/ 5
  • 6. Exception Hierarchy Contd .. • Exception class is used for exceptional conditions that user programs should catch • It is used to create your own custom exception types • RuntimeException is a subclass of Exception • It is automatically defined for the programs that you write • Includes things such as division by zero and invalid array indexing http://improvejava.blogspot.in/ 6
  • 7. Error • It defines exceptions that are not expected to be caught under normal circumstances by your program • Stack overflow is an example of such an error http://improvejava.blogspot.in/ 7
  • 8. Type of Exceptions • There are two types of exceptions in Java • Unchecked exceptions • Checked exceptions http://improvejava.blogspot.in/ 9CM604.46 8
  • 9. Unchecked Exceptions • The compiler does not check to see if a method handles or throws these exceptions • Hence the name unchecked • They need not be included in any method’s throws list http://improvejava.blogspot.in/ 9
  • 10. Checked Exceptions • The compiler checks whether these exceptions were handled in the method • That must be included in a method’s throws list • Compiler error occurs if these exceptions were not handled by the methods http://improvejava.blogspot.in/ 10
  • 11. Unchecked Exceptions Examples Table 46.1 Unchecked Exception http://improvejava.blogspot.in/ 11
  • 12. Checked Exceptions Examples Table 46.2 Checked Exception http://improvejava.blogspot.in/ 12
  • 13. Summary • All exception types are subclasses of the built-in class Throwable • Throwable is at the top of the exception class hierarchy • Exception, Error are subclasses of Throwable • Types of exception • Unchecked exceptions • Checked exceptions http://improvejava.blogspot.in/ 13
  • 14. Quiz 1. Which exceptions types are not expected to be caught under normal circumstances by your program A. Error B. Exceptions C. None http://improvejava.blogspot.in/ 14
  • 15. Frequently Asked Questions 1. Explain about the various types of Exceptions 2. List out the various checked and unchecked exceptions http://improvejava.blogspot.in/ 15