First of all, i am going to explain some importaint points of error and exception:-
- Exception and Error both are the sub class of java.lang.Throwable class.
- Error is a subclass of Throwable that indicates serious problems, which is reasonable application should not try to catch. Errors are abnormal conditions.
- We can handle Exceptions at runtime but Errors we can not be handle.
- Exceptions are objects that representing the logical errors that occur at run time and it makes JVM enters into the state of "ambiguity".
- Objects which are automatically created by the JVM for representing these run time errors are known as Exceptions.
Difference Between Exceptions and Errors:-
- In Exception we have two types 1.Checked Exception 2.Unchecked Exceptions but, Errors are by default unchecked exceptions.
- If an exception occurs, we can handle it by using try and catch block. But, If Error occurs we can handle it program execution to be terminated.
- Exceptions are related to application where as Errors are related to environment in which is running application.
- Exception are of type java.lang.Exception but, Errors are of type java.lang.Error. Error will run at run time.
- Checked Exceptions will known to compiler so we need to handle exceptions at compile time otherwise compile time Error will come.
- Unchecked Exception will come at run time which need to be handle by try and catch blocks.