
-----------------------------------
Martin
Thu Oct 13, 2005 9:42 pm

try-catch-finally
-----------------------------------
Quick question.

What's the difference between #1 and #2:

///#1
try  {
	foo();
}
catch (SomeException e) {
	bar();
}
finally {
	baz();
}


///#2
try  {
	foo();
}
catch (SomeException e) {
	bar();
}
baz();

Thanks in advance.

-----------------------------------
wtd
Thu Oct 13, 2005 9:52 pm


-----------------------------------
What happens if an exception other than SomeException is thrown?

The first example will run baz.  The latter won't.

-----------------------------------
Martin
Thu Oct 13, 2005 10:18 pm


-----------------------------------
Ahh, got it. Thanks.

-----------------------------------
Finaltank
Fri Oct 14, 2005 3:26 pm


-----------------------------------
What about interrupted exception?

try
{
Thread.sleep (Time in parenthesis)
}
catch (InterruptedException e)
{
}


-----------------------------------
Hikaru79
Fri Oct 14, 2005 4:27 pm


-----------------------------------
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).
