SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Tendances (20)

Properties and indexers in C#
Properties and indexers in C#Properties and indexers in C#
Properties and indexers in C#
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
interface in c#
interface in c#interface in c#
interface in c#
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
 
Java string handling
Java string handlingJava string handling
Java string handling
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAWHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVA
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
 
Java basics and java variables
Java basics and java variablesJava basics and java variables
Java basics and java variables
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
javathreads
javathreadsjavathreads
javathreads
 

En vedette (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
 

Similaire à Types of exceptions

Introduction to java exceptions
Introduction to java exceptionsIntroduction to java exceptions
Introduction to java exceptions
Sujit Kumar
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in Java
Vadym Lotar
 
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
 

Similaire à Types of exceptions (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
 
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
 
Training material exceptions v1
Training material   exceptions v1Training material   exceptions v1
Training material exceptions v1
 

Plus de 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

  • 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