Thread
类的getDefaultUncaughtExceptionHandler()
方法返回当线程由于未捕获的异常而突然终止时调用的默认处理程序。 如果返回的值为null
,则没有默认值。
语法
public static Thread.UncaughtExceptionHandler getDefaultUncaughtExceptionHandler()
返回
- 此方法返回默认处理程序。
示例
public class JavaetDefaultExceptioneExp implements Runnable
{
public void run()
{
// prints thread name
System.out.println("Currently running thread is: " + Thread.currentThread().getName());
}
public static void main(String[] args)
{
JavaetDefaultExceptioneExp g1 = new JavaetDefaultExceptioneExp();
Thread t1 = new Thread(g1);
Thread t2 = new Thread(g1);
// this will call run() function
t1.start();
t2.start();
// returns the default handler
Thread.UncaughtExceptionHandler handler = Thread
.getDefaultUncaughtExceptionHandler();
System.out.println(handler);
}
}
执行上面示例代码,得到以下结果:
null
Currently running thread is: Thread-0
Currently running thread is: Thread-1