My code does display the message
package com.codegym.task.task25.task2505;
/*
No idiots
*/
public class Solution {
public static void main(String[] args) throws InterruptedException {
MyThread myThread = new Solution().new MyThread("super secret key");
myThread.start();
}
public class MyThread extends Thread {
private String secretKey;
public MyThread(String secretKey) throws InterruptedException {
this.secretKey = secretKey;
setUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
setDaemon(false);
}
@Override
public void run() {
throw new NullPointerException("This is an example");
}
private class MyUncaughtExceptionHandler implements UncaughtExceptionHandler{
@Override
public void uncaughtException(Thread t, Throwable e) {
try {
Thread.sleep(500);
} catch (InterruptedException interruptedException) {
interruptedException.printStackTrace();
}
System.out.println(String.format("%s, %s, %s", secretKey, Thread.currentThread().getName(), "this is an exammple"));
}
}
}
}