SlideShare une entreprise Scribd logo
1  sur  18
Disclaimer:This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
JAVA EXCEPTION
   HANDLING
       Ashwin Anand V
       Email:ashwinanand99@gmail.com
       Facebook id:ashwinanand99@gmail.com
Exceptions
• What are they?
  – An exception is a representation of an error condition
    or a situation that is not the expected result of a
    method.
  – Exceptions are built into the Java language and are
    available to all program code.
How are they used?
  – Exceptions fall into two categories:
     • Checked Exceptions
     • Unchecked Exceptions
  – Checked exceptions are inherited from the core Java
    class Exception. They represent exceptions that are
    frequently considered “non fatal” to program
    execution
  – Checked exceptions must be handled in your code, or
    passed to parent classes for handling.
Examples
  – Checked exceptions include errors such as “array index
    out of bounds”, “file not found” and “number format
    conversion”.
  – Unchecked exceptions include errors such as “null
    pointer”.
How do you handle exceptions?
  – Exception handling is accomplished through the “try –
    catch” mechanism, or by a “throws” clause in the
    method declaration.
  – For any code that throws a checked exception, you can
    decide to handle the exception yourself, or pass the
    exception “up the chain” (to a parent class).
  – To handle the exception, you write a “try-catch” block.
    To pass the exception “up the chain”, you declare a
    throws clause in your method or class declaration.
  – If the method contains code that may cause a checked
    exception, you MUST handle the exception OR pass the
    exception to the parent class (remember, every class
    has Object as the ultimate parent)
• Try-Catch Mechanism
 – Wherever your code may trigger an exception, the
   normal code logic is placed inside a block of code
   starting with the “try” keyword:
 – After the try block, the code to handle the exception
   should it arise is placed in a block of code starting with
   the “catch” keyword.
 – You may also write an optional “finally” block. This
   block contains code that is ALWAYS executed, either
   after the “try” block code, or after the “catch” block
   code.
 – Finally blocks can be used for operations that must
   happen no matter what (i.e. cleanup operations such
   as closing a file)
• Example
  – try {
    … normal program code
    }
    catch(Exception e) {
    … exception handling code
    }
Example




Output:
Division by zero.
After catch statement.
Throw
• It is possible for your program to throw an exception
  explicitly
  throw TrrowableInstance
• Here, TrrowableInstance must be an object of type
  Throwable or a subclass Throwable
Example




   Output:
   Caught inside demoproc.
   Recaught: java.lang.NullPointerException: demo
Finally
• It is used to handle premature execution of a method (i.e.
  a method open a file upon entry and closes it upon exit)
• finally creates a block of code that will be executed after
  try/catch block has completed and before the code
  following the try/catch block
• finally clause will execute whether or not an exception is
  thrown
Example
Output
 inside procA
 procA's finally
 Exception caught
 inside procB
 procB's finally
 inside procC
 procC's finally
• If this presentation helped you, please visit
  our page facebook.com/baabtra and like it.
  Thanks in advance.

• www.baabtra.com | www.massbaab.com |ww
  w.baabte.com
Thank you
Contact Us

Contenu connexe

Tendances

Week7 exception handling
Week7 exception handlingWeek7 exception handling
Week7 exception handling
Alpesh Oza
 
14 exception handling
14 exception handling14 exception handling
14 exception handling
jigeno
 
Design byexceptions
Design byexceptionsDesign byexceptions
Design byexceptions
Asif Tasleem
 

Tendances (20)

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
 
Exception handling in asp.net
Exception handling in asp.netException handling in asp.net
Exception handling in asp.net
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception handling in python
Exception handling in pythonException handling in python
Exception handling in python
 
Week7 exception handling
Week7 exception handlingWeek7 exception handling
Week7 exception handling
 
Exception handling basic
Exception handling basicException handling basic
Exception handling basic
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Java
 
Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception Handling
 
summarizer16fev16_Exceptions
summarizer16fev16_Exceptionssummarizer16fev16_Exceptions
summarizer16fev16_Exceptions
 
Presentation1
Presentation1Presentation1
Presentation1
 
14 exception handling
14 exception handling14 exception handling
14 exception handling
 
Exceptions
ExceptionsExceptions
Exceptions
 
12 exception handling
12 exception handling12 exception handling
12 exception handling
 
Keywords for exceptions.44
Keywords for exceptions.44Keywords for exceptions.44
Keywords for exceptions.44
 
Design byexceptions
Design byexceptionsDesign byexceptions
Design byexceptions
 
Exception handling in ASP .NET
Exception handling in ASP .NETException handling in ASP .NET
Exception handling in ASP .NET
 

En vedette (7)

Html tags
Html tagsHtml tags
Html tags
 
MIS
MISMIS
MIS
 
XML
XMLXML
XML
 
Flowchart& algorithom
Flowchart& algorithomFlowchart& algorithom
Flowchart& algorithom
 
XML
XMLXML
XML
 
Stack and heap
Stack and heapStack and heap
Stack and heap
 
XML
XMLXML
XML
 

Similaire à Java exeception handling

exceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.pptexceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.ppt
yjrtytyuu
 
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
HayomeTakele
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
priyankazope
 
Exception handling chapter15
Exception handling chapter15Exception handling chapter15
Exception handling chapter15
Kumar
 

Similaire à Java exeception handling (20)

exceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.pptexceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.ppt
 
Exception handling in .net
Exception handling in .netException handling in .net
Exception handling in .net
 
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-java.ppt
exception-handling-in-java.pptexception-handling-in-java.ppt
exception-handling-in-java.ppt
 
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
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2
 
Javasession4
Javasession4Javasession4
Javasession4
 
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
 
Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
 
Exception hierarchy
Exception hierarchyException hierarchy
Exception hierarchy
 
Exception handling in JAVA
Exception handling in JAVAException handling in JAVA
Exception handling in JAVA
 
06 exceptions
06 exceptions06 exceptions
06 exceptions
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception handling chapter15
Exception handling chapter15Exception handling chapter15
Exception handling chapter15
 
Exception
ExceptionException
Exception
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
 

Plus de baabtra.com - No. 1 supplier of quality freshers

Plus de baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Java exeception handling

  • 1.
  • 2. Disclaimer:This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 3. JAVA EXCEPTION HANDLING Ashwin Anand V Email:ashwinanand99@gmail.com Facebook id:ashwinanand99@gmail.com
  • 4. Exceptions • What are they? – An exception is a representation of an error condition or a situation that is not the expected result of a method. – Exceptions are built into the Java language and are available to all program code.
  • 5. How are they used? – Exceptions fall into two categories: • Checked Exceptions • Unchecked Exceptions – Checked exceptions are inherited from the core Java class Exception. They represent exceptions that are frequently considered “non fatal” to program execution – Checked exceptions must be handled in your code, or passed to parent classes for handling.
  • 6. Examples – Checked exceptions include errors such as “array index out of bounds”, “file not found” and “number format conversion”. – Unchecked exceptions include errors such as “null pointer”.
  • 7. How do you handle exceptions? – Exception handling is accomplished through the “try – catch” mechanism, or by a “throws” clause in the method declaration. – For any code that throws a checked exception, you can decide to handle the exception yourself, or pass the exception “up the chain” (to a parent class). – To handle the exception, you write a “try-catch” block. To pass the exception “up the chain”, you declare a throws clause in your method or class declaration. – If the method contains code that may cause a checked exception, you MUST handle the exception OR pass the exception to the parent class (remember, every class has Object as the ultimate parent)
  • 8. • Try-Catch Mechanism – Wherever your code may trigger an exception, the normal code logic is placed inside a block of code starting with the “try” keyword: – After the try block, the code to handle the exception should it arise is placed in a block of code starting with the “catch” keyword. – You may also write an optional “finally” block. This block contains code that is ALWAYS executed, either after the “try” block code, or after the “catch” block code. – Finally blocks can be used for operations that must happen no matter what (i.e. cleanup operations such as closing a file)
  • 9. • Example – try { … normal program code } catch(Exception e) { … exception handling code }
  • 11. Throw • It is possible for your program to throw an exception explicitly throw TrrowableInstance • Here, TrrowableInstance must be an object of type Throwable or a subclass Throwable
  • 12. Example Output: Caught inside demoproc. Recaught: java.lang.NullPointerException: demo
  • 13. Finally • It is used to handle premature execution of a method (i.e. a method open a file upon entry and closes it upon exit) • finally creates a block of code that will be executed after try/catch block has completed and before the code following the try/catch block • finally clause will execute whether or not an exception is thrown
  • 15. Output inside procA procA's finally Exception caught inside procB procB's finally inside procC procC's finally
  • 16. • If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. • www.baabtra.com | www.massbaab.com |ww w.baabte.com