java.lang.Thread.getUncaughtExceptionHandler()%uA0方法返回调用的处理时,该线程突然终止,由于未捕获到异常。
声明
以下是java.lang.Thread.getUncaughtExceptionHandler()方法的声明
public Thread.UncaughtExceptionHandler getUncaughtExceptionHandler()
参数
-
NA
返回值
此方法不返回任何值。
异常
-
NA
例子
下面的例子显示java.lang.Thread.getUncaughtExceptionHandler()方法的使用。
package com.yiibai import java.lang.* public class ThreadDemo implements Runnable { Thread t public ThreadDemo() { t = new Thread(this) // this will call run() function t.start() } public void run() { // prints thread name System.out.println("Thread = " + t.getName()) /* returns the handler invoked when this thread abruptly terminates due to an uncaught exception. */ Thread.UncaughtExceptionHandler handler = t.getUncaughtExceptionHandler() System.out.println(handler) } public static void main(String[] args) { new ThreadDemo() new ThreadDemo() } }
让我们来编译和运行上面的程序,这将产生以下结果:
Thread = Thread-0 java.lang.ThreadGroup[name=main,maxpri=10] Thread = Thread-1 java.lang.ThreadGroup[name=main,maxpri=10]