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

Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling pptJavabynataraJ
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packagesVINOTH R
 
Core java concepts
Core java  conceptsCore java  concepts
Core java conceptsRam132
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and OperatorsMarwa Ali Eissa
 
Java exception handling
Java exception handlingJava exception handling
Java exception handlingBHUVIJAYAVELU
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introductionSohanur63
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsNewCircle Training
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handlingNahian Ahmed
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVASURIT DATTA
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaMOHIT AGARWAL
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in javaNilesh Dalvi
 

Mais procurados (20)

Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling ppt
 
Generics in java
Generics in javaGenerics in java
Generics in java
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
 
Exception handling
Exception handlingException handling
Exception handling
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
 
Java threading
Java threadingJava threading
Java threading
 
Data types in java
Data types in javaData types in java
Data types in java
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
Java input
Java inputJava input
Java input
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 

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
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handlingkamal kotecha
 

Destaque (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
 

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
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in JavaVadym Lotar
 
Exceptionhandling
ExceptionhandlingExceptionhandling
ExceptionhandlingNuha Noor
 
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
 

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
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
 
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
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
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
 

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