in JAVA by (20.8k points)
What is exception in java?

1 Answer

0 votes
by (32.2k points)

An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program’s instructions.

When an error occurs within a method, the method creates an object and hands it off to the runtime system. The object, called an exception object, contains information about the error, including its type and the state of the program when the error occurred. Creating an exception object and handing it to the runtime system is called throwing an exception.

After a method throws an exception, the runtime system attempts to find something to handle it. The set of possible “somethings” to handle the exception is the ordered list of methods that had been called to get to the method where the error occurred. The list of methods is known as the call stack.

Related questions

0 votes
0 votes
asked May 2, 2021 in JAVA by sharadyadav1986 (31.7k points)
+2 votes
asked May 30, 2020 in JAVA by Robindeniel (20.8k points)
0 votes
asked May 3, 2021 in JAVA by Robindeniel (20.8k points)