2. EXCEPTION
Exception is a problem that aries during
the execution of a program.when
exception occurs the normal flow of the
program is disturb and the program
terminates abnormally.
3. REASONS FOR EXCEPTIONS:-
An exception can occur for many different
reasons. Following are some scenarios
where an exception occurs:-
A user has entered an invalid data.
A file that needs to be opened cannot be
found.
A network connection has been lost in the
middle of communications or the JVM has
run out of memory.
4. ERROR
An Error is any unexpected result
obtained from a program during
execution.
Errors should be handled by the
programmer, to prevent them from
reaching the user.
Unhandled errors may manifest
themselves as incorrect results or
behavior, or as abnormal program
termination.
5. TYPES OF Error
RUN TIME Error- Dividing and integer by
zero ,
Acessing an elemet which is out of
bound,try to store a value which is
incompatilbe with class or variable type,
passing parameter that are not in valid
range.
COMPILE TIME Error -missing
semicolomn,
missing brackets in class or method,
missing double quotes in string,
use of undefined operator.
6. EXCEPTION HANDLING
Exception Handling is a mechanism to
handle runtime errors .with thw help of
exception handling we can easily find an
error and easily remove or solved error
that occur during the execution of a
program.
7. Steps for handling exception
Find the problem .
Infrom that error has occurred.
Receive the error information
Tak ecorretive action.
Hit the exception
Throw the exception
Catch the exception
Handle the exception
8.
9. COMMON JAVAEXCEPTION
Arithmetic exception.
Array store exception.
I/O exception.
Null pointer Exception.
Security exception.
String out of bound exception.
Number format exception.
File not find exception.
11. Types of JAVA EXCEPTION
Checked Exception-The classes which
directly inherit Throwable class except
RuntimeException and Error are known as
checked exceptions e.g. IOException,
SQLException etc. Checked exceptions are
checked at compile-time.
Unchecked Exception-The classes which
inherit RuntimeException are known as
unchecked exceptions e.g.
ArithmeticException, NullPointerException,
ArrayIndexOutOfBoundsException etc.
Unchecked exceptions are not checked at
compile-time, but they are checked at
runtime.
12. Example of exception handling in
java
public class JavaExceptionExample{
public static void main(String args[]){
try{
int data=100/0;
}
catch(ArithmeticExceptione)
{System.out.println(e);}
System.out.println("rest of the code...");
}
}