Get the App
SLTechnology News&Howtos  ›  Development  › 

How does JAVA handle uncaught exceptions

Shulou Source: shulou.com Published: 2022-06-02 11:41:48 11月01日 Update

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

Tags: Threads processing processors methods articles examples success results face-to-face try clear active no that is value information interest just at the same time the situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Information Docker MySQL Shulou Tech Info