This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exeptions with Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exeptions with Threads" Watch "Exeptions with Threads" New topic

Exeptions with Threads

Sagar kanchi
Ranch Hand

Joined: Oct 07, 2005
Posts: 50
class Th extends Thread{
public void run(){System.out.println("1"); int a = 10/0;
public static void main(String[] args) {
Th th1 = new Th();th1.start();//1
Th th2 = new Th(); th2.start();//2
Th th3 = new Th();th3.start();//3 } }
Here the output we get is as follows
java.lang.ArithmeticException: / by zero
java.lang.ArithmeticException: / by zero
java.lang.ArithmeticException: / by zero

My doubt is as follows :
We are starting from main thread creating 3 more threads.
Each thread is throwing Exceptions.
I am not handling any exceptions still its executing successfully.
I mean we are neither providing any handler nor throwing any Exception.
So, it should stop the execution at line number 1.
But why this is happening.

Where there are more wonders there is less knowledge
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Because, it thrown exception in this method.

Java Developer, Thailand
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Exeptions with Threads
Similar Threads
Thread question
Creating multiple children threads
why thread priority is not working here
How to interrupt or stop the threads