Java
Java
Objectives
• Introduction
• What exceptions are for
Exception Handling in Java • Catching & Throwing exceptions
• Exception Specifications
• Standard Java Exceptions
• Exceptions and Polymorphism
Explained By: Abhishek
• The finally clause
Lokesh
Sumit
• Resource Management
Karan • Uncaught Exceptions
Introduction Error
• Due to design errors or coding errors, our • An error may produce an incorrect output or
programs may fail in unexpected ways during may terminate the execution of the program
execution. An exception is a condition that is abruptly or even may cause the system to
caused by run time error in the program. The crash. So it is our responsibility to detect and
purpose of the exception handling mechanism manage the error properly.
is to provide a means to detect and report an
“ecxceptional circumstances” .
02-06-2024
Example conclusion
class error2
{
public static void main(String arg[])
– Exceptions are a powerful error handling
{
int a=10;
mechanism.
int b=5;
int c=5; – Exceptions in Java are built into the language.
int x,y;
{
try
– Exceptions can be handled by the programmer
}
x=a/(b-c);
(try-catch), or handled by the Java environment
{
catch(ArithmeticException e)
(throws).
System.out.println(“Division by Zero”);
}
Y=a/(b-c);
– Exception handling can only hide the errors.
System.out.println(“y=“+y);
} – It cannot correct the errors.
}