satish training ppt

20
INDUSTRIAL TRAINING PRESENTATION ON EXCEPTION HANDLING IN JAVA Submitted to :- Mr.r.s.s.rawat (H.O.D. of it department) Submitted by:- Satish ahirwar B.e. VIIth sem enroll no.:-0601it131046

Upload: satish10121995

Post on 11-Apr-2017

34 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: Satish training ppt

INDUSTRIAL TRAINING

PRESENTATION ON

EXCEPTION HANDLING IN

JAVASubmitted to :- Mr.r.s.s.rawat

(H.O.D. of it department)

Submitted by:- Satish ahirwarB.e. VIIth sem

enroll no.:-0601it131046

Page 2: Satish training ppt
Page 3: Satish training ppt

Contents

What is an Exception .

What happen when an Exception is occurs.

Runtime Error.

Exception class Hierarchy.

Types of Exception.

Exception Handling Keywords.Methods for printing the details of an

Exception.

Page 4: Satish training ppt

What is an Exception?In general, Exception are run time errors caused due to logical mistakes occurred during program execution because of its wroung input.

Examples:-ArithmaticException.ArrayOutOfBoundException.IOException.FileNotFoundException.SQLException.etc.

Page 5: Satish training ppt

Exception Example(ArithmeticException)

1 class DivByZero {2

3

public static void main(String args[]) { System.out.println(3/0);

4 System.out.println(“Pls. print me.”);5 }6 }

Page 6: Satish training ppt

What Happens When an Exception Occurs?

When an exception occurs within a method, themethod creates an exception object and hands it offto the runtime system.

Exception object contains information about the error,including its type and the state of the program when theerror occurred.

Page 7: Satish training ppt

Example: Default Exception Handling

Displays this error messageException in thread "main" java.lang.ArithmeticException: / by zero

at DivByZero.main(DivByZero.java:3)

Default exception handler

–Provided by Java runtime Prints out exception description Prints the stack trace

Page 8: Satish training ppt

Runtime Error

It is also unwanted unexpected problem .

A run time error is occurs due to the system resource problem for run time error it is not possible to provide the solution programmatically.

Examples:-StackOverFlowErrorOutOfMemoryErrorEtc.

Page 9: Satish training ppt

Exception class Hierarchy

Page 10: Satish training ppt

Types Of Exception

In java there are two types of exception .

Checked Exception-the checked Exceptions are recognised by compiler.

Unchecked Exception.- The Unchecked Exceptions are not recognised by comiler.

Page 11: Satish training ppt

Checked Exception

Page 12: Satish training ppt

Unchecked Exception

ERROR

OutOfMemoryError

StackOverFlowErroretc,.

Page 13: Satish training ppt

Exception Handling Keywords

try

catch

finally

throws

throw

Page 14: Satish training ppt

syntax

try { // Risky Code } catch(type of exception-1 object-1) { // Handling Code } catch(type of exception-2 object-2) { // Handling Code} finally { // Resource releasing logic. }

Page 15: Satish training ppt

throw Keyword

Java allows you to throw exceptions (generate exceptions)throw <exception object>;

An exception you throw is an object

You have to create an exception object in the same way you create any other object

Example:throw new ArithmeticException(“testing...”);

Page 16: Satish training ppt

throws Keyword

Throws is a java Keyword use to by paas generated exception from present method to calling methods.

Syntax Methodname() throws <Exceptionobject>{//throw Exception object}

Page 17: Satish training ppt

Methods for printing the details of an Exception.

In java there are three methods for Printing the details of an Exception

• Public void PrintstackTrace(){name of the Exception: Discription of the Exception:Location of the Exception}

• Public String toString (){Name of the Exception :Discription of the Exception.}

• Public String getmessage(){Discription of the Exception}

Page 18: Satish training ppt
Page 19: Satish training ppt
Page 20: Satish training ppt

60

Thank You!