Java Reference
In-Depth Information
}
};
Thread thd = new Thread(r);
Thread.UncaughtExceptionHandler uceh;
uceh = new Thread.UncaughtExceptionHandler()
{
public void uncaughtException(Thread t,
Throwable e)
{
System.out.println("Caught
throwable
"+e+" for thread "+t);
}
};
thd.setUncaughtExceptionHandler(uceh);
uceh = new Thread.UncaughtExceptionHandler()
{
public void uncaughtException(Thread t,
Throwable e)
{
System.out.println("Default
uncaught
exception handler");
System.out.println("Caught
throwable
"+e+" for thread "+t);
}
};
thd.setDefaultUncaughtExceptionHandler(uceh);
thd.start();
}
}
When you run this application, you will observe the following output:
Caught throwable java.lang.ArithmeticException: / by zero
for thread Thread[Thread- 0,5,main]
You also will not see the default uncaught exception handler's output because the
default handler is not called. To see that output, you must comment out
thd.setUncaughtExceptionHandler(uceh); . If you also comment out
Search WWH ::




Custom Search