"jobs" <jo**@webdos.comwrote in message
news:bf**********************************@a28g2000 hsc.googlegroups.com...
>
Use finally to close/dispose of connections. The Finally block always
executes.
If your purpose in creating a catch block is to simply close/dispose of
stuff before re-throwing the error then simply don't bother with the
catch
block at all. The whole point of the finally block is to perform tidy
up
code that must occur whether or not an exception is being thrown.
--
Anthony Jones - MVP ASP/ASP.NET
Thanks, But I do still need to make sure I close/dispose when an error
occurs. Can I do that in Appliation_error sub of the Global.asax? If
so, how? If not I will have to rethrow the same exception? how?
Let me emphasis what I've already said:-
"The Finally block always executes."
That means even if the flow of code is now in an error condition the code in
the finally block will still execute. Thats why its there. If code in the
finally block didn't execute when an error occured it wouldn't have any
point in being there since it would be no different than putting code at the
bottom of the try block.
So its in the finally block that you would place close/dispose code.
C# provides the using() alternative which allows you to define a block of
code that uses a disposable object that must always be disposed when
execution leaves block. The manner of leaving the block is immaterial,
either by normal code execution or due to an exception.
--
Anthony Jones - MVP ASP/ASP.NET