public class Main implements Thread.UncaughtExceptionHandler {

public static void main(String[] args) {
    Main main=new Main();
    Thread childThread=new ChildThread();
    childThread.start();
    childThread.setUncaughtExceptionHandler(main);
    for(int i=0; i < 100; i ++) {
        try {
            Thread.sleep(100);
            //System.out.println("Main thread, loop "+i);
        }
        catch(InterruptedException e) {
            break;
        }
    }
}

public void uncaughtException(Thread t, Throwable e) {
    System.out.println("We are in " + Thread.currentThread().getClass().getName() + " and this is correct!");
    System.out.println("Caught thread "+t.getClass().getName()+" - we're back in main thread! (this is fucking lie)");
    }
}

class ChildThread extends Thread {

@Override
public void run() {
    int j=0;
    while(true) {
        try {
            Thread.sleep(100);
            System.out.println("Child thread, loop "+j++);
            if(j>=10) {
                throw new RuntimeException("Test!");
            }

        }
        catch(InterruptedException e) {
            break;
        }
    }
  }
}
