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

PPTX
Access specifiers(modifiers) in java
PPT
Abstract class in java
PPTX
Operators in java
PPS
Java Exception handling
PDF
Java threads
PPTX
Exception Handling in Java
PPTX
Java exception handling
PPTX
Methods in java
Access specifiers(modifiers) in java
Abstract class in java
Operators in java
Java Exception handling
Java threads
Exception Handling in Java
Java exception handling
Methods in java

What's hot (20)

PPT
Method overriding
PPTX
Control statements in java
PPTX
Method overloading
PPTX
Exception handling in Java
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
PPTX
C# Asynchronous delegates
PPTX
String Builder & String Buffer (Java Programming)
PDF
Arrays in Java
ODP
Multithreading In Java
PPTX
PPTX
Operators in java
PPTX
Exception handling
PDF
Enumeration in Java Explained | Java Tutorial | Edureka
PPTX
Constructor in java
PPTX
Java program structure
PPTX
Constructor in java
PPTX
Control structures in java
PPT
Final keyword in java
PPT
Exception handling
Method overriding
Control statements in java
Method overloading
Exception handling in Java
Basic Concepts of OOPs (Object Oriented Programming in Java)
C# Asynchronous delegates
String Builder & String Buffer (Java Programming)
Arrays in Java
Multithreading In Java
Operators in java
Exception handling
Enumeration in Java Explained | Java Tutorial | Edureka
Constructor in java
Java program structure
Constructor in java
Control structures in java
Final keyword in java
Exception handling
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