What is the Thread getDefaultUncaughtExceptionHandler() in Java?
This static function Thread.getDefaultUncaughtExceptionHandler() from the java.lang package helps to return the default handler.
This exception will be raised only when a running thread abruptly dismisses due to an uncaught exception.
- If the returned value by this function is
null, there is no default.
This method in the
Threadclass is purely used for exception handling purposes.
Syntax
static Thread.UncaughtExceptionHandler
getDefaultUncaughtExceptionHandler()
Parameters
The function doesn’t take any parameters.
Code
The below-mentioned code helps to show the exception, null, which means there is no default uncaught exception.
// Load Thread classimport java.lang.Thread;// Main classpublic class EdPresso implements Runnable {Thread thr;public EdPresso() {thr = new Thread(this);//calling run() functionthr.start();}// run() methodpublic void run() {// printing thread nameSystem.out.println("Thread is:" + thr.getName());/* returning the default handler that is invoked when a thread stops due to uncaught exception. */Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();System.out.println(handler);}public static void main(String[] args) {new EdPresso();}}