• Post Reply Bookmark Topic Watch Topic
  • New Topic

try catch finally  RSS feed

 
kiruthiga arumugam
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi to all

try{
....
System.exit(0);
}
catch(){//code ABC}


will this code ABC execute??
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If only there were some way to test that...

Do you have javac installed on your computer?
 
Pramod P Deore
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think the code in the catch() block will be excuted.
beacause after System.exit(0) the program will be terminated...
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pramod deodeore:
I don't think the code in the catch() block will be excuted.
beacause after System.exit(0) the program will be terminated...


The problem with the example is the "...." could be anything. How do you know that that section of code won't throw an exception?

Henry
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure about the bit saying catch() {

What is in the ()?
 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't the following code not only exit the currently running program but also exits the entire JVM that the program is running in so that if there are other programs running in the same JVM that they get terminated too?

System.exit(0);

If System.exit() does exit the whole JVM what is the proper way to terminate only the current application? You can't throw an unchecked exception because that would only terminate the currently running thread, right?
[ October 11, 2008: Message edited by: Kaydell Leavitt ]
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are right, but we haven't heard how Kiruthiga Arumugam got the class to run.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!