Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Variable scope and try and catch
Message
From
17/09/2003 17:02:29
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00829818
Message ID:
00830111
Views:
28
This message has been marked as a message which has helped to the initial question of the thread.
Dmitry,

Plamen already got it, but you may have missed it. If you intialize your variables with null prior to the try/catch, it should still work.
SqlCommand sc = null;
DataReader dr = null;
// etc.
try
{
    sc = new SqlCommand();
    // and all the rest of the stuff
}
catch (SqlException ex)
{
}
~~Bonnie

>>>>
>>Don't want to answer for Plamen, but you didn't get it right. You have to initialize all variables prior to try/finally block.
>
>That's not my understanding. The idea of TRY is to try to initialize things to see if they work and if they don't catch them. I know I have to declare them prior to TRY but it is different from initializing. Perhaps Plamen or Bonnie will correct me or you :-)
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform