Listing 6: File ThreadTest.java — Illustrates ThreadGroup.uncaughtException

class MyThread extends Thread
{
    public void run()
    {
        System.out.println("Throwing in " +
                           "MyThread");
        throw new RuntimeException();
    }
}

class ThreadTest
{
    public static void main(String[] args)
    {
        MyThread t = new MyThread();
        t.start();
        try
        {
            Thread.sleep(1000);
        }
        catch (Exception x)
        {
            System.out.println("Caught it");
        }
        System.out.println("Exiting main");
    }
}

/* Output:
Throwing in MyThread
java.lang.RuntimeException
        at MyThread.run(ThreadTest.java:7)
Exiting main
*/
— End of LIsting —