aspose file tools
The moose likes Beginning Java and the fly likes try catch finally Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "try catch finally" Watch "try catch finally" New topic
Author

try catch finally

kiruthiga arumugam
Greenhorn

Joined: Sep 29, 2008
Posts: 8
hi to all

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


will this code ABC execute??
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

If only there were some way to test that...

Do you have javac installed on your computer?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

I don't think the code in the catch() block will be excuted.
beacause after System.exit(0) the program will be terminated...


Life is easy because we write the source code.....
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16681
    
  19

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32611
    
    4
Are you sure about the bit saying catch() {

What is in the ()?
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 679

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
Sheriff

Joined: Oct 13, 2005
Posts: 32611
    
    4
I think you are right, but we haven't heard how Kiruthiga Arumugam got the class to run.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: try catch finally
 
Similar Threads
csv file
AJAX jsp response
doubt in try,catch,finally
java regular expression problem
Initializing the HashSet, which 1 is preferable?