» » » Difference between error and exception in java

  • Exception and Error both are sub classes of java.lang.Throwable class.
  • We can handle Exceptions at runtime but Errors we can not handle.

  • Exceptions are the objects representing the logical errors that occur at 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 Exceptions.
  • An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions.
difference between error and exception handling

  Difference Between Exceptions and Errors

  • If exception occurs we can handle it by using try and catch block. If Error occurs we can noyt handle it , program execution will be terminated.
  • In Exception we have two types
    1. Checked Exception
    2.Unchecked Exceptions
  • Error are by default unchecked exceptions.
  • Exceptions are related to application where ad Error are related to environment in which application is running.

  • Exception are of type java.lang.Exception
  • Errors are of type java.lang.Error
  • Error will run at run time.
  • In Exceptions Checked Exceptions will known to compiler so we need to handle these exceptions at compile time itself otherwise compile time Error will come.
  • Unchecked Exception will come at run time need to handle by using try and catch blocks.

Read More About Exceptions here:
  1. Exception Handling Introduction
  2. try catch finally in Java
  3. User Defined Exceptions in Java
  4. Throw vs throws 
  5. Final vs finally vs finalize()


Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu