Click here to Skip to main content
15,896,201 members
Articles / Programming Languages / C# 4.0

Try - finally alternative

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
5 Jun 2011CPOL 5.6K   1  
There are times when "try"-related wrappers can be useful. For example, a Try() wrapper DLL written in a language other than C# could pass an Exception parameter to the Finally clause indicating whether the Try clause succeeded. For example:Try (() => {DoSomething();}, (Exception inner_ex)...

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
5 Jun 2011JV9999
Not really, because what if your finally block would contain more lines of code than the single line you have in your example? That would make it already much harder to read.Secondly, you are misusing the Dispose method. You shouldn't invoke anything in it, especially not the Action, you...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Unknown
Embedded systems programmer since 1994.

Comments and Discussions