Syntax aside, what is the difference between
try { } catch() { } finally { x = 3; }
and
try { } catch() { } x = 3;
edit: in .NET 2.0?
so
try { throw something maybe x = 3 } catch (...) { x = 3 }
is behaviourally equivalent?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Depends on the language as there might be some slight semantic differences, but the idea is that it will execute (almost) always, even if the code in the try block threw an exception.
In the second example, if the code in the catch block returns or quits, the x = 3 will not be executed. In the first it will.
In the .NET platform, in some cases the execution of the finally block won’t occur: Security Exceptions, Thread suspensions, Computer shut down :), etc.