Vishal Joshi
What is difference between Errors and Exceptions?

What is difference between Errors and Exceptions?

By Vishal Joshi in .NET on Sep 08 2022
  • Uday Dodiya
    Sep, 2022 13

    Exceptions and errors both are subclasses of Throwable class. The error indicates a problem that mainly occurs due to the lack of system resources and our application should not catch these types of problems. Some of the examples of errors are system crash error and out of memory error. Errors mostly occur at runtime that’s they belong to an unchecked type.

    Exceptions are the problems which can occur at runtime and compile time. It mainly occurs in the code written by the developers. Exceptions are divided into two categories such as checked exceptions and unchecked exceptions.

    Difference : Error & Exception
    1 Type
    Classified as an unchecked type
    Classified as checked and unchecked

    2 Package
    It belongs to java.lang.error
    It belongs to java.lang.Exception

    3 Recoverable/ Irrecoverable
    It is irrecoverable
    It is recoverable

    4 When Occured
    It can’t be occur at compile time
    It can occur at run time compile time both

    5 Example
    OutOfMemoryError ,IOError
    NullPointerException , SqlExceptio

    • 2
  • Tuhin Paul
    Feb, 2023 24

    In programming, both errors and exceptions are types of problems that can occur when running code, but they have different meanings and are handled differently.

    An error is a problem that occurs at runtime that prevents the program from continuing. Errors are typically caused by a system-level issue, such as a lack of memory or a network failure, or by a programming mistake, such as dividing by zero or accessing an invalid memory location. When an error occurs, the program usually terminates immediately, and the developer must identify and fix the problem before running the program again.

    An exception, on the other hand, is a problem that occurs at runtime that can be handled by the program. Exceptions are typically caused by incorrect input or unexpected conditions, such as a file not found or a network connection being lost. When an exception occurs, the program can “catch” the exception and take appropriate action, such as displaying an error message or retrying the operation.

    In most programming languages, exceptions are represented by objects that contain information about the problem, such as an error message and a stack trace. The developer can use try-catch blocks to handle exceptions and take appropriate action, such as logging the error or prompting the user to retry the operation.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS