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 :
//statements that may cause an exception
catch (exception(type) e(object))
//error handling code
public static void main (String args)
System.out.println("Rest of code...");
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.
Have a friend to whom you would want to share this course?