0 votes
in Java by

What is the difference between error and exception in java? This question is very popular for java interview. It always asked in telephonic and face-to-face interview. So, Please provide suitable answer for it.

1 Answer

0 votes
by (4.4k points)

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.

Share:- Whatsapp Facebook Facebook

Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.