1.

What do you understand about exceptions in the context of the Java programming language? What are the different types of exceptions in Java?

Answer»

An EXCEPTION is an unwelcome or unexpected occurrence that occurs during the execution of a program, i.e. at run time, and disturbs the program's usual flow of instructions. The APPLICATION can detect and handle exceptions. When a method throws an exception, it creates an object. The exception object is the name given to this object. It contains details about the exception, such as the name and DESCRIPTION of the error, as well as the program's state at the time the error occurred.

An exception can happen for a variety of reasons. Here are a few examples:

  • User input that is not valid.
  • Failure of a device.
  • A network connection is lost.
  • Physical restraints (eg: out of disk memory).
  • Code flaws.
  • Attempting to open a file that is currently unavailable.

Java defines several different types of exceptions for its various class libraries. Users can also define their exceptions in Java. The following are the different types of exceptions in Java:

  • Built-in Exceptions: Exceptions that are present in Java libraries are known as built-in exceptions. These exceptions are appropriate for explaining specific mistake scenarios.
    • Checked Exceptions: Checked exceptions are also known as compile-time exceptions SINCE the COMPILER checks them at compile time.
    • Unchecked Exceptions: Unchecked exceptions are the polar opposite of checked exceptions. These exceptions will not be checked by the compiler at compilation time. To put it another way, if a programme throws an unchecked exception, even if we don't handle or declare it, the programme won't throw a compilation error.
  • User-Defined Exceptions: In some cases, Java's built-in exceptions are unable to adequately explain a scenario. In such instances, users can design their exceptions, known as 'user-defined Exceptions’.


Discussion

No Comment Found