SlideShare a Scribd company logo
3
Most read
11
Most read
15
Most read
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

More Related Content

PPT
Exception Handling in JAVA
PPTX
Exception handling c++
PPTX
Java exception handling
PPTX
Java constructors
PPTX
Static Members-Java.pptx
PPT
9. Input Output in java
PPT
Java exception
PPTX
This keyword in java
Exception Handling in JAVA
Exception handling c++
Java exception handling
Java constructors
Static Members-Java.pptx
9. Input Output in java
Java exception
This keyword in java

What's hot (20)

PPTX
Java Methods
PPTX
Exception handling in java
PPS
Java Exception handling
PPTX
Exception handling
PPTX
Control flow statements in java
PPTX
Control statements in java
PPTX
Control structures in java
PDF
Java Collection framework
PPSX
Comparable and comparator – a detailed discussion
PPTX
Presentation on-exception-handling
PDF
Constants, Variables and Data Types in Java
PPTX
Applets in java
PPT
Method overriding
PPTX
Control Statements in Java
PPSX
Exception Handling
PPTX
Super keyword in java
PPSX
Collections - Maps
PDF
Class and Objects in Java
PPTX
java interface and packages
PPTX
OOPS In JAVA.pptx
Java Methods
Exception handling in java
Java Exception handling
Exception handling
Control flow statements in java
Control statements in java
Control structures in java
Java Collection framework
Comparable and comparator – a detailed discussion
Presentation on-exception-handling
Constants, Variables and Data Types in Java
Applets in java
Method overriding
Control Statements in Java
Exception Handling
Super keyword in java
Collections - Maps
Class and Objects in Java
java interface and packages
OOPS In JAVA.pptx
Ad

Viewers also liked (7)

PPT
Multi catch statement
PPTX
Presentación2
PPTX
Eventos party mix
PPTX
Sonrrisa brillante estomatologia
PPT
Campanha Marketing TV Tambaú 2013
PPT
Various io stream classes .47
PPTX
Eventos party mix[1]
Multi catch statement
Presentación2
Eventos party mix
Sonrrisa brillante estomatologia
Campanha Marketing TV Tambaú 2013
Various io stream classes .47
Eventos party mix[1]
Ad

Similar to Types of exceptions (20)

PPTX
Event handling
PPTX
Java_Prog_-_UNIT-IV_Part_A_Modinnfy.pptx
DOCX
Unit5 java
PPTX
Exceptions in Java
PPT
oop-unit-iii-ppt.pptexceptionhandlingobjectorientedprogramming
DOCX
What is an exception in java?
PPTX
OBJECT ORIENTED PROGRAMMING_Unit3_NOTES first half.pptx
PPT
Exception Handling Java
PDF
Exception_edit_2024acexception handling.pdf
PPTX
Lec-01 Exception Handling in Java_javatpoint.pptx
PPTX
Exceptions in java
PPTX
UNIT III 2021R.pptx
PPTX
UNIT III 2021R.pptx
PPT
Computer Object Oriented Programming - Chapter 4 - Excption Handling.ppt
PPT
Exception
PPT
Exception
PPT
Exception
PPT
Exception
PPT
Exception
Event handling
Java_Prog_-_UNIT-IV_Part_A_Modinnfy.pptx
Unit5 java
Exceptions in Java
oop-unit-iii-ppt.pptexceptionhandlingobjectorientedprogramming
What is an exception in java?
OBJECT ORIENTED PROGRAMMING_Unit3_NOTES first half.pptx
Exception Handling Java
Exception_edit_2024acexception handling.pdf
Lec-01 Exception Handling in Java_javatpoint.pptx
Exceptions in java
UNIT III 2021R.pptx
UNIT III 2021R.pptx
Computer Object Oriented Programming - Chapter 4 - Excption Handling.ppt
Exception
Exception
Exception
Exception
Exception

More from myrajendra (20)

PPT
Fundamentals
PPT
Data type
PPTX
Hibernate example1
PPTX
Jdbc workflow
PPTX
2 jdbc drivers
PPTX
3 jdbc api
PPTX
4 jdbc step1
PPTX
Dao example
PPTX
Sessionex1
PPTX
Internal
PPTX
3. elements
PPTX
2. attributes
PPTX
1 introduction to html
PPTX
Headings
PPTX
Forms
PPT
PPTX
Views
PPTX
Views
PPTX
Views
PPT
Starting jdbc
Fundamentals
Data type
Hibernate example1
Jdbc workflow
2 jdbc drivers
3 jdbc api
4 jdbc step1
Dao example
Sessionex1
Internal
3. elements
2. attributes
1 introduction to html
Headings
Forms
Views
Views
Views
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