exception handling in java exception handling in java with examples exception handling in java pdf exception handling in java interview questions what is exception handling in java what is exception handling in java with example define exception handling in java definition of exception handling in java exception handling in java interview questions and answers interview questions on exception handling in java exception handling in java examples types of exception handling in java exception handling in java ppt example of exception handling in java exception handling in java tutorial exception handling program in java exception handling exceptions in java exception handling in java with example exception handling in java with example programs exception handling in java with example pdf exception handling in java with example ppt exception handling in java sample program exception handling in java with examples program ppt exception handling in java best practices exception handling mechanism in java
Exception Handling:
Defintion
Of Exception Handling:
An Exception is an object occurred at Run time Which Describes A Nature of the
message.the nature of the message can be either System Error Message or User
Friendly
Error Message.
For Example:
ArithmeticException ae=new ArithmeticException(“div By Zero”);
Div by zero -------> Nature Of the Message.
ae------------------> Object of the Arithmetic Exception.
Handling the Exceptions:
Handling the Exceptions are nothing but converting System Error Messages into User
Friendly error Messages.
Handling
the exceptions are of two types. They are
1) By using
predefined exception process
2) User defined
Exception Handling
1) By using predefined Exception process:
To Handle the exception process we have five keywords they are.
1) try
2) catch
3) finally
4) throws
5) throw
Syntax :
try
{
// Block of Statements
// Which causes errors at runtime
}
Catch(ExceptionType1 obj1)
{
//Block Of Stmts
// Which Provides user friendly error mssg
}
Catch(ExceptionType2 obj2)
{
//Block Of Stmts
//
Which Provides user friendly error mssg
}
………………..
……………….
Catch(ExceptionTypen objn)
{
//Block Of Stmts
// Which Provides user friendly error mssg
}
Finally
{
}
1) try:
It is One of the block contains the block of statements which Causes problematic
Statements.
2) Catch():
It is one of the block in which we write block of statements. Which will provide User
Friendly Messages i.e; It
suppress System Errors Messages
And Generates User friendly
messages. If
Any Exception Is Occurred then appropriate catch block is executed.
3) Finally:
It is one of the block contains block of statements which will perform relinquish
(close/terminate)
resources which are obtained in
try block.
4) throws :
Throws is
keyword which always gives an indication of specific Method (calling function)
to place
common exception methods(Called
Functions)
OR
Throws is
keyword which will express or describes the exceptions
which are occurring as
part of common method Body.
Syntax:
Returntype MethodName(listof formalparameters)throws
exceptiontype1,exceptiontope2……….exceptiontypeN
{
//Block of Statements;
}
//Block of Statements;
}
5) Throw:
Throw is
Keyword Used for Raising or generating the Exception
Which Are occurring as
part of method Body.
OR
Throw is Keyword Which Carrying The Created Exception From Method body to Method
Heading and
Handovers to throws Keyword.
Syntax:
<classname> <objname>=new <classname>(obj);
Throw(obj);
- What is Exception and list of Exceptions and exception hierarchy
- What are user defined Exceptions and guide lines
- Example For User Defined Exceptions
No comments:
Post a Comment