• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread Prob

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class Thread2 implements Runnable{
public void run(){
System.out.println("run");

throw new RuntimeException("Exception::::");

}
public static void main(String args[]){
Thread2 tt=new Thread2();
Thread t=new Thread(tt);
t.start();
try {

t.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

System.out.println("main");
}
}


In this above prob the answere should come like

/*
run
Exception in thread "Thread-0" java.lang.RuntimeException: Exception::::
at Thread2.run(Thread2.java:6)
at java.lang.Thread.run(Unknown Source)
main
*/


but the output is like
/*
run
main
Exception in thread "Thread-0" java.lang.RuntimeException: Exception::::
at Thread2.run(Thread2.java:6)
at java.lang.Thread.run(Unknown Source)
*/

Can someone give a solution to this

//This Question is taken from TestsNow.com
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java will print out the stack trace for any uncaught exception, on the current thread.
Since the exception was deliberately thrown on a different thread, the printed stack trace can occur before or after "main" gets printed.
[ June 18, 2008: Message edited by: Frank Zito ]
 
Screaming fools! It's nothing more than a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic