• 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

Catch RunTimeException

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I wrote a building block of thread like this:
while(true) {
try {
// doing something
}
catch(RunTimeException e) {
//restart the thread
}
}
but I my question is that if the thread catch a RunTimeException,
would it still run(in the while(true)) or it world die.
If it would die, how could I do to restart the thread
Thanks for every replies.
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A thread with a run method that looks like this will only halt when an Error is thrown, System.exit() is called, or some variant of the above happens:

The run() method is, as far as you're concerned, "the thread." The thread will run until the run() method finishes, at which point it will be ready for death. Thus while the run() method doesn't return, the thread is still running.
[ October 28, 2003: Message edited by: David Weitzman ]
[ October 29, 2003: Message edited by: David Weitzman ]
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David,
Whether wrong or right, good or bad, these things bother me, and I feel obliged to correct you.


for all intensive purposes


I believe the phrase is, "for all intents and purposes".
(I don't believe I know what an intensive purpose is. Perhaps you can enlighten me?)
Good Luck,
Avi.
 
Ricky Wang
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David Weitzman:
A thread with a run method that looks like this will only halt when an Error is thrown, System.exit() is called, or some varient of the above happens:

The run() method is, for all intensive purposes, "the thread." The thread will run until the run() method finishes, at which point it will be ready for death. Thus while the run() method doesn't return, the thread is still running.


So when I catch a RunTimeException like ArrayOutBoundOfIndexException, I just do nothing and the thread will still run properly?
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm no grammarian, but I've modified my post in a way which should avoid offending either the grammer gods or any our saloon guests
 
Avi Abrami
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I'm no grammarian, but I've modified my post in a way which should avoid offending either the grammer gods or any our saloon guests


Lucky I didn't mention the spelling mistakes
Avi.
 
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry, but why are you trying to catch RuntimeException. It usually means programmer screw up the code, like not initialize an object (nullpointer), etc.
If you are doing, should'nt you try to catch InterruptedException?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic