SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Exception handling
Exception handlingException handling
Exception handling
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++
 
Exception handling
Exception handlingException handling
Exception handling
 
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
 
Abstract class
Abstract classAbstract class
Abstract class
 
Java - Exception Handling
Java - Exception HandlingJava - Exception Handling
Java - Exception Handling
 
Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#
 
Switch statements in Java
Switch statements  in JavaSwitch statements  in Java
Switch statements in Java
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exception handling
Exception handlingException handling
Exception handling
 
this keyword in Java.pptx
this keyword in Java.pptxthis keyword in Java.pptx
this keyword in Java.pptx
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
Java threads
Java threadsJava threads
Java threads
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Abstraction in java.pptx
Abstraction in java.pptxAbstraction in java.pptx
Abstraction in java.pptx
 

Destaque

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
 

Destaque (7)

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]
 

Semelhante a 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
 
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
 
Training material exceptions v1
Training material   exceptions v1Training material   exceptions v1
Training material exceptions v1Shinu Suresh
 
Exception handling in java.pptx
Exception handling in java.pptxException handling in java.pptx
Exception handling in java.pptxARUNPRANESHS
 

Semelhante a 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
 
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
 
Exception handling in java.pptx
Exception handling in java.pptxException handling in java.pptx
Exception handling in java.pptx
 

Mais 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 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