Uncaught Exception In Java
Chapter:
Exception Handling
Last Updated:
08-06-2017 13:59:10 UTC
Program:
/* ............... START ............... */
public class JavaUncaughtException {
public static void main(String args[]) {
int a = 0;
int b = 100 / a;
}
}
/* ............... END ............... */
Output
Exception in thread "main" java.lang.ArithmeticException: / by zero
at ExceptionHandling.JavaUncaughtException.main(JavaUncaughtException.java:19)
Notes:
-
If the exceptions are not caught in a try/catch block, then what you often see in practice is Java print the exception stack trace.
- The java.lang.ThreadGroup.uncaughtException() method is called by the Java Virtual Machine when a thread in this thread group stops because of an uncaught exception, and the thread does not have a specific Thread.UncaughtExceptionHandler.
- When an uncaught exception occurs, the JVM does the following:
- It calls a special private method, dispatchUncaughtException(), on the Thread class in which the exception occurs.
- It then terminates the thread in which the exception occurred.
Tags
Uncaught Exception, Java