Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] [OT] C# question -- try / catch / finally



On 21 November 2013 17:53, Godwin Stewart <gstewart@example.com> wrote:
> If the finally block is executed in both cases, whether the exception is
> thrown or not, what is the point in having a special construct for it at
> all?

Basically, if the run is interrupted for some reason (return,
unhandled non-security-related exception), the finally block will
still run before returning the ball to wherever.

try {
   stupid_thing();
} catch (Exception) {
   return 1;
} finally {
   return 0;
}

...will return 0. The try/catch clauses will (within reason) hand the
ball over to the finally clause if anything happens which causes them
to, err, not happen any more. It's good for closing sockets and stuff
like that.


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links