Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Using or TryCatchFinally

Reply
Thread Tools

Using or TryCatchFinally

 
 
K Viltersten
Guest
Posts: n/a
 
      10-24-2009
I can't decide whether i should deploy the
using statement or Try-Catch-Finally
statement.

I'd prefer using because it's more compact
and automagically disposes stuff.

On the other hand, i can't be sure that the
DB is working, so i might end up with an
ugly exception, which requires an explicit
try/catch to handle...

Suggestions?

--

Regards
Konrad Viltersten
--------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.
 
Reply With Quote
 
 
 
 
Marvin Landman
Guest
Posts: n/a
 
      10-24-2009
K Viltersten wrote:
> I can't decide whether i should deploy the
> using statement or Try-Catch-Finally statement.
>
> I'd prefer using because it's more compact
> and automagically disposes stuff.
>
> On the other hand, i can't be sure that the DB is working, so i might
> end up with an ugly exception, which requires an explicit try/catch to
> handle...
>
> Suggestions?


IDisposable resource = ...;
using (resource) {
...
}

is functionally equivalent to

IDisposable resource = ...;
try {
...
} finally {
if (resource != null)
resource.Dispose ();
}

(The compiler creates a temp variable to ensure that resource is not
changing.)

As you can see there is no catch block in the using statement
implementation.

So if you need a catch block then you have to create a catch block even
if you choose the using statement over a try-finally block.

Marvin
 
Reply With Quote
 
 
 
 
K Viltersten
Guest
Posts: n/a
 
      10-24-2009
<snip>
> So if you need a catch block then you have to create
> a catch block even if you choose the using statement
> over a try-finally block.


Dang...

Thanks to both of you.

--

Regards
Konrad Viltersten
--------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error page using the Application_Error void dosnt work when using DIV for a please wait message s_erez@hotmail.com ASP .Net 2 12-24-2004 12:11 PM
Implementing the TryCatchFinally interface correctly Manavendra Gupta Java 1 03-07-2004 04:32 PM
no code in webform using vs.net, but in webform using notepad timmso ASP .Net 1 12-12-2003 04:30 PM
Using GetOleDbSchemaTable to get SQL Server Field Description - using pete ASP .Net 1 08-29-2003 10:50 AM
Re: MVP? Index error on nested element using System.xml but NOT using msxml??? William F. Robertson, Jr. ASP .Net 1 06-25-2003 08:08 PM



Advertisments