Difference Between Error and Exception in Java

JavaServer Side ProgrammingProgramming

In this post, we will understand the difference between error and exception.

Error

  • It is classified as an unchecked type.

  • It belongs to the class ‘java.lang.error’.

  • It can’t be recovered from.

  • It can't occur at compile time.

  • Examples of errors include −

    • ‘OutOfMemoryError’

    • ‘IOError’

Exception

  • It can be classified into unchecked and checked exceptions.

  • It belongs to the class ‘java.lang.Exception’.

  • It can be recovered from.

  • It can occur at runtime as well as compile time.

  • Examples of exceptions include −

    • NullPointerException

    • SqlException

raja
Published on 24-Mar-2021 13:18:23
Advertisements