Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 try-catch-finally
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Martin




PostPosted: Thu Oct 13, 2005 9:42 pm   Post subject: try-catch-finally

Quick question.

What's the difference between #1 and #2:

code:
///#1
try  {
        foo();
}
catch (SomeException e) {
        bar();
}
finally {
        baz();
}


///#2
try  {
        foo();
}
catch (SomeException e) {
        bar();
}
baz();


Thanks in advance.
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Thu Oct 13, 2005 9:52 pm   Post subject: (No subject)

What happens if an exception other than SomeException is thrown?

The first example will run baz. The latter won't.
Martin




PostPosted: Thu Oct 13, 2005 10:18 pm   Post subject: (No subject)

Ahh, got it. Thanks.
Finaltank




PostPosted: Fri Oct 14, 2005 3:26 pm   Post subject: (No subject)

What about interrupted exception?
code:

try
{
Thread.sleep (Time in parenthesis)
}
catch (InterruptedException e)
{
}
Hikaru79




PostPosted: Fri Oct 14, 2005 4:27 pm   Post subject: (No subject)

InterruptedException is just a subclass of Exception. You can catch exceptions specifically (like in your example) so that you can deal with different exceptions in different ways, or you can catch a generic "Exception" which handles any subclasses of Exception (most of them).
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: