• Post Reply Bookmark Topic Watch Topic
  • New Topic

Catch RunTimeException  RSS feed

 
Ricky Wang
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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.
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • 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 ]
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • 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.
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!