Types of Exceptions      http://improvejava.blogspot.in/   1
ObjectivesOn completion of this period, you would be able to learn:   • Exception hierarchy   • Types of exceptions       ...
Recap• In the last class, you have studied about the concept  of multi-catch statements• We have also written a sample pro...
Exception Hierarchy      The following diagram shows exception hierarchy                                 Throwable        ...
Exception Hierarchy                      Contd ..• All exception types are subclasses of the built-in  class Throwable• Th...
Exception Hierarchy                        Contd ..• Exception class is used for exceptional conditions  that user program...
Error• It defines exceptions that are not expected to be  caught under normal circumstances by your  program• Stack overfl...
Type of Exceptions• There are two types of exceptions in Java   • Unchecked exceptions   • Checked exceptions             ...
Unchecked Exceptions• The compiler does not check to see if a method  handles or throws these exceptions   • Hence the nam...
Checked Exceptions• The compiler checks whether these exceptions were  handled in the method• That must be included in a m...
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 excepti...
Quiz1. Which exceptions types are not expected to be   caught under normal circumstances by your   program  A. Error  B. E...
Frequently Asked Questions1. Explain about the various types of Exceptions2. List out the various checked and unchecked   ...
Upcoming SlideShare
Loading in …5
×

Types of exceptions

581 views
524 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
581
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Types of exceptions

  1. 1. Types of Exceptions http://improvejava.blogspot.in/ 1
  2. 2. ObjectivesOn completion of this period, you would be able to learn: • Exception hierarchy • Types of exceptions http://improvejava.blogspot.in/ 2
  3. 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. 4. Exception Hierarchy The following diagram shows exception hierarchy Throwable Error ExceptionExamples(Out of memory errorStack overflow errors) RuntimeException Examples (ArithmeticException, NullpointerException, Fig. 46.1 Exception hierarchy IndexOutofBoundsException) 4 http://improvejava.blogspot.in/
  5. 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. 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. 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. 8. Type of Exceptions• There are two types of exceptions in Java • Unchecked exceptions • Checked exceptions http://improvejava.blogspot.in/ 9CM604.46 8
  9. 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. 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. 11. Unchecked Exceptions Examples Table 46.1 Unchecked Exception http://improvejava.blogspot.in/ 11
  12. 12. Checked Exceptions Examples Table 46.2 Checked Exception http://improvejava.blogspot.in/ 12
  13. 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. 14. Quiz1. 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. 15. Frequently Asked Questions1. Explain about the various types of Exceptions2. List out the various checked and unchecked exceptions http://improvejava.blogspot.in/ 15

×