Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][tlug] [OT] C# question -- try / catch / finally
- Date: Thu, 21 Nov 2013 16:53:48 +0000
- From: Godwin Stewart <gstewart@example.com>
- Subject: [tlug] [OT] C# question -- try / catch / finally
- User-agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1
Hi all, Way off-topic, I know, but there are some coders hanging out here and I'm hoping one of you will be able to answer this. So, I'm learning about C# and the .NET framework while developing for Windows Phone 8. Not my choice, but hey, you do what's asked of you if you want to keep your job, right? I'm not that wet behind the ears that I don't know about exception handling, it's this curious "finally" block that has me stumped. I can see how it works but I really can't see the point in it. Given this snippet of code: try { doSomething(); doSomethingElse(); areWeDoneAlready(); } catch (SomeKindOfException) { kaboom(); } finally { cleanup(); } If doSomething() executes fine with no exceptions being raised then execution goes on to doSomethingElse() and then areWeDoneAlready(), then jumps straight to the finally block and cleanup() is executed. If, however, doSomething() does raise SomeKindOfException then execution is transferred immediately to the relevant catch block and kaboom() is executed before the finally block is. 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? Surely this is functionally equivalent: try { doSomething(); doSomethingElse(); areWeDoneAlready(); } catch (SomeKindOfException) { kaboom(); } cleanup(); Is there any type of circumstance where a finally block actually brings something to the table? -- Godwin Stewart -- <gstewart@example.com>
- Follow-Ups:
- Re: [tlug] [OT] C# question -- try / catch / finally
- From: Bruno Raoult
- Re: [tlug] [OT] C# question -- try / catch / finally
- From: jep200404
- Re: [tlug] [OT] C# question -- try / catch / finally
- From: Benjamin Tayehanpour
- Re: [tlug] [OT] C# question -- try / catch / finally
- From: Darren Cook
- Re: [tlug] [OT] C# question -- try / catch / finally
- From: jep200404
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] Program to Mirror Individual Files?
- Next by Date: Re: [tlug] Program to Mirror Individual Files?
- Previous by thread: [tlug] OpenSUSE V.13 out in a few hours! Give it a try!
- Next by thread: Re: [tlug] [OT] C# question -- try / catch / finally
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links