KEMBAR78
Error managing and exception handling in java | PPTX
Error Management and ExceptionHandling
in
JAVA
9/7/2018
OVERVIEW
 Introduction to error and theirtypes
 Examples of errors
 Introduction to exception and exception handling
 Common java exceptions
 Examples of exceptionhandling
9/7/2018
TYPES
 Mistakes in program that leads to unsuccessful execution of program
 May produce an incorrect output or may terminate the execution of program
Types of error
I. Compile time error
o It won’t create .class file
 Causes:
omissing semicolons
ouse of undeclared variables
omisspelling of identifiers and keywords,etc
9/7/2018
II. Run time error
o Program may compile successfully but doesn’t run correctly
o It will create .class file
o Causes: dividing an integer by zero,accessing an element out of the
bound of an array, converting invalid string into number, etc
9/7/2018
I. INTRODUCTION TO ERROR AND ITS TYPES
(CONTINUED)
II. EXAMPLES OF ERRORS
Example1: Compile Time error
Example2: Run Time error
Fig. Execution of Example1 program
Fig. Execution of Example2 program
9/7/2018
III. INTRODUCTION TO EXCEPTION AND
EXCEPTION HANDLING
 Condition caused by a run time error in the program
 Exception object created by java compiler when it encounters an error and throws it
 If we want to continue execution of remaining code then the exception should be
caught and show a user defined error message- known as exception handling
Exceptions can be handled by following below procedures:
9/7/2018
HANDLE
the
exception
CATCH
the
exception
THROW
the
exception
HIT the
exception
IV. COMMON JAVA EXCEPTIONS
9/7/2018
V. EXAMPLES OF EXCEPTION HANDLING
9/7/2018
1:Try and catch for exception handling
Output:
EXAMPLES OF EXCEPTION HANDLING
(CONTINUED)
9/7/2018
2:Using multiple catch blocks exception handling
Output:
CONCLUSION
Errorsarenormalforprogrammers-noprogram
canbeexecutedsimplyinafirsttry…
Exceptionhandlingmethods:usedinlarge
programswherechancesofexceptionsarehuge!
9/7/2018
Thankyou...9/7/2018

Error managing and exception handling in java

  • 1.
    Error Management andExceptionHandling in JAVA 9/7/2018
  • 2.
    OVERVIEW  Introduction toerror and theirtypes  Examples of errors  Introduction to exception and exception handling  Common java exceptions  Examples of exceptionhandling 9/7/2018
  • 3.
    TYPES  Mistakes inprogram that leads to unsuccessful execution of program  May produce an incorrect output or may terminate the execution of program Types of error I. Compile time error o It won’t create .class file  Causes: omissing semicolons ouse of undeclared variables omisspelling of identifiers and keywords,etc 9/7/2018
  • 4.
    II. Run timeerror o Program may compile successfully but doesn’t run correctly o It will create .class file o Causes: dividing an integer by zero,accessing an element out of the bound of an array, converting invalid string into number, etc 9/7/2018 I. INTRODUCTION TO ERROR AND ITS TYPES (CONTINUED)
  • 5.
    II. EXAMPLES OFERRORS Example1: Compile Time error Example2: Run Time error Fig. Execution of Example1 program Fig. Execution of Example2 program 9/7/2018
  • 6.
    III. INTRODUCTION TOEXCEPTION AND EXCEPTION HANDLING  Condition caused by a run time error in the program  Exception object created by java compiler when it encounters an error and throws it  If we want to continue execution of remaining code then the exception should be caught and show a user defined error message- known as exception handling Exceptions can be handled by following below procedures: 9/7/2018 HANDLE the exception CATCH the exception THROW the exception HIT the exception
  • 7.
    IV. COMMON JAVAEXCEPTIONS 9/7/2018
  • 8.
    V. EXAMPLES OFEXCEPTION HANDLING 9/7/2018 1:Try and catch for exception handling Output:
  • 9.
    EXAMPLES OF EXCEPTIONHANDLING (CONTINUED) 9/7/2018 2:Using multiple catch blocks exception handling Output:
  • 10.
  • 11.