線程類的 getDefaultUncaughtExceptionHandler() 方法返回當線程由於未捕獲的異常突然終止時調用的默認處理程序。如果返回值為空,則沒有默認值。
用法
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
相關用法
- Java Thread getContextClassLoader()用法及代碼示例
- Java Thread getThreadGroup()用法及代碼示例
- Java Thread getId()用法及代碼示例
- Java Thread getState()用法及代碼示例
- Java Thread getName()用法及代碼示例
- Java Thread getStackTrace()用法及代碼示例
- Java Thread getPriority()用法及代碼示例
- Java Thread toString()用法及代碼示例
- Java Thread interrupted()用法及代碼示例
- Java Thread setDefaultUncaughtExceptionHandler()用法及代碼示例
- Java Thread suspend()用法及代碼示例
- Java Thread destroy()用法及代碼示例
- Java Thread holdLock()用法及代碼示例
- Java Thread setContextClassLoader()用法及代碼示例
- Java Thread sleep()用法及代碼示例
- Java Thread isInterrupted()用法及代碼示例
- Java Thread enumerate()用法及代碼示例
- Java Thread notify()用法及代碼示例
- Java Thread resume()用法及代碼示例
- Java Thread activeCount()用法及代碼示例
注:本文由純淨天空篩選整理自 Java Thread getDefaultUncaughtExceptionHandler() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。