Explain the concepts of Exceptions in Java.Exceptions are errors that occur at runtime and disrupt the normal flow of execution of instructions in a program.
An exception object is created by the method in which an error occurs which is then handed over to the runtime system. This process is called throwing an exception. The object contains the details of the error, its type, etc.
An exception handler is the code that executes after an exception is encountered. The runtime method searches the call stack to find an appropriate method containing the code for handling the exception. The runtime system after receiving the exception tries to find a suitable way to handle it.
When the type of exception thrown matches the type of exception that can be handled, the exception is passed on to the handler so as to catch the exception. The three types of exceptions are:
checked exceptions, errors and runtime exceptions.