What happens to uncaught exceptions in Java?

For a program:

class Test {

public static void main(String args[ ]) {

int a = 0;

int b = 5 / a;



When you run the above program following things will happen:

1) Java run time system finds that it is a divide by zero situation.

2) Exception object is created.

3) The exception is thrown.

4) Program execution stops.

5) Since, there is no exception handler defined, default exception handler is used to catch the exception.

6) Termination of program happens with the following output:

java.lang.ArithmeticException: / by zero

at Test.main(Test.java:4)

Leave a Reply