Course Content

Course Content

Description

Exception Handling in Java

In the previous video of our course we understood about Static binding in Java and Dynamic binding in Java programming language. In this video we are going to see that what is Exception Handling in Java with an example.

An Exception in Java is a problem that arises during the Execution of a program. When an exception occurs during execution of program, the normal flow of the program is disrupted and the program/Application terminates abnormally.

Exception in Java can occur at Runtime as well as at Compile time. They are known as Runtime exceptions and Compile time exceptions in Java programming.

Exception handling in Java programming language is a mechanism to handle runtime errors such as ClassNotFound, IO, SQL, Remote etc.... 

The advantage of Exception handling are as follows :
1. The core advantage of exception handling is to maintain the normal flow of the application.
2. Exception normally disrupts the normal flow of the application that is why we use exception handling.

According to sun microsystems there are three types of exceptions,
1. Checked exception in Java
2. Unchecked Exception in Java
3. Error in Java

Checked Exception in Java : A checked exception is an exception that occurs at the compile time, these are also known as compile time exceptions. Example : IOException, SQLException etc...

Unchecked Exception in Java : An unchecked exception is an exception that occurs at the time of execution, these are also called as Runtime exceptions. Example : Programming bugs, such as logic errors or improper use of an API.

Error in Java : Error is irrecoverable. Example : OutOfMemoryError, VirtualMachineError, AssertionError etc...

'Try' is used to handle exception in Java and contains error code. While 'Catch' contains solution for Try block.
Syntax for Try :
try
{
//statements that may cause an exception
}
catch (exception(type) e(object))
{
//error handling code
}

Example :
class exe
{
public static void main (String args[])
{
try
{
int a=20/0;
}
catch(ArithmeticException e)
{
System.out.println(e);
}
System.out.println("Rest of code...");
}
}
Output :
Java.lang.ArithmeticException/by zero
Best of code...

So, in this video we have seen that what are types of Exceptions in Java, and how Exception handling in Java works with example. Now, in our next video we will see about File Input and Output in Java language.

FAQs

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere