What are the differences between an Exception class and an Error class in Java?
Both an Exception class and an Error class are subclasses of java.lang.Throwable class, we can able to handle the exceptions at runtime but the errors we cannot handle.
- Exceptions are the objects representing the logical errors that occur at the run time and makes JVM enters into the state of "ambiguity".
- The objects which are automatically created by the JVM for representing these run time errors are known as an Exception. An Error is a subclass of Throwable class that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions.
- If an exception occurs we can handle it by using try and catch block. If an error occurs we can not handle it, program execution will be terminated.
- In Exception we have two types, one is Checked Exception and another is Unchecked Exception, Error is by default unchecked Exception.
- An exception is of type java.lang.Exception and an error is of type java.lang.Error.
Published on 29-May-2019 14:19:27