How does JAVA handle uncaught exceptions
This article mainly introduces how JAVA deals with uncaptured exceptions, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it.
JVM provides us with an uncaught exception handling mechanism for threads, through the setUncaughtExceptionHandler method of Thread:
Public void setUncaughtExceptionHandler (UncaughtExceptionHandler eh)
You can set the uncaught exception handler for the current thread. For example, the following example successfully catches an exception divided by 0 by setting uncaughtExceptionHandler:
Public static void main (String [] args) throws InterruptedException {Thread t = new Thread (new UncaughtException.Run ())
T.setUncaughtExceptionHandler (new Thread.UncaughtExceptionHandler () {@ Overridebr/ > @ Override@Overridesuper (name))
}
@ Override@Override@Override