Would anyone explain why an uncaught exception thrown by one of the threads in a mulit-thread environment WILL NOT cause the program to terminate immediately? Where, how and by what is the exception handled?
1. A program has many threads (user and daemon). 2. When a thread encounters an uncaught exception, it dies (not the program). A thread is a part of the whole system. "It" is not the system. 3. If there are still user threads running, the program cannot terminate. Of course, if the program has only one user thread and if that thread encounters an uncaught exception, the program will terminate.
Thanks Paul. You cleared my wrong belief in that any uncaught exceptions will terminate the program. Perhaps this is due to the fact that most of the time I only ran the main thread and every uncaught exception in it cause it to stop. As noted by Jane, I've here a program which can issue the situation for those interested:
The output is: Starting Thread-0 Starting Thread-1 Main Thread ends! Running Thread-0 Running Thread-1 Thread-0 Thread-1 Thread-0 Thread-1 Thread-0 Thread-1 Thread-0 java.lang.RuntimeException at Test$2.run(Test.java:25) Thread-0 Thread-0 Thread-0 Thread-0 Thread-0 Thread-0 Process exit...
[This message has been edited by Kevin Yip (edited June 05, 2001).] [This message has been edited by Kevin Yip (edited June 05, 2001).]
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop