• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Exeptions with Threads

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Th extends Thread{
public void run(){System.out.println("1"); int a = 10/0;
System.out.println("2");}
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
1
java.lang.ArithmeticException: / by zero
at Th.run(Th.java:6)
1
java.lang.ArithmeticException: / by zero
at Th.run(Th.java:6)
1
java.lang.ArithmeticException: / by zero
at Th.run(Th.java:6)

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.
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because, it thrown exception in this method.

 
You didn't tell me he was so big. Unlike this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic