Exception Handling and types of exception handling in java programming
Exception handling in java programming
Exception handling means avoiding abnormal termination of the program.Different types of error occur in our program,such as user errors,logic errors or system errors.When an exception occurs, it makes further execution of the program impossible.Java offers an excellent exception
handling mechanism which is easy to understand and implement.Whenever an error occurs during the execution of a program,it throws an exception.If the exception is not handled properly,
the program execution is terminated.
What is an exception handling mechanism in java?
Exception handling is a mechanism that enables programs to detect and handle errors before they occur rather than allowing them to occur and suffering the consequences.
Handling Exception In Java
Exception handling in java is accomplished by using
five keywords. try,catch,throw,throws and finally.
Java exception categorized into three types
- Checked exception —> Also known as compile time exception
- Unchecked exception —> Also known as runtime exception
- Errors
Some Example for the runtime exceptions are
ArithmeticException ---> Errors that occur when dividing by zero
NumberformatException ---> converting string to integer
ArrayIndexOutOfBoundException ---> assigns an array size and the user
accesses beyond the size.
NullPointerException ---> Its an error that occurs when a string variable
is assigned null and an instruction is issued to print the string length.
All these exceptions are available in throwable classes.
This is available in the lang package.
lang package is the default package.
Advantages of exception handling in java
- The separation of error-handling code from normal code
- A logical grouping of error types
- The ability to propagate errors up the call stack
Comments
Post a Comment