output :
Exception in thread "main" runningz
java.lang.RuntimeException: main
at A.main(A.java:19)
Exception in thread "puspen" java.lang.RuntimeException: run
at A.run(A.java:9)
at java.lang.Thread.run(Unknown Source)
till now i have learnt that when an exception occurs , the program exits leaving all the code . But here, exception is occuring at
//line3 first, so as per the rule, an exception has occured so the program should exit, printing the exception. But here first the "
main" exception occur, then before printing the stack trace of "
main" exception, it prints the "
running" from the
run() method. And then after printing the "
main" exception stack trace, it prints the another exception which occur in
run() method.
It can b clearly seen that even after the exception has occured, the another
thread (
here "puspen") gets executes. But why is it so ? Shouldn't the program get terminate ?