Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Variable scope and try and catch
Message
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00829818
Message ID:
00830059
Views:
26
This message has been marked as a message which has helped to the initial question of the thread.
>Plamen and Bonnie,
>
>Thank you both for replies.
>
>I was not trying to rely on a variable initialized in TRY in the CATCH. But I was hoping that I could rely on the variable initialized in TRY in the code after the CATCH and FINALLY. But it seems that I have to do it all in FINALLY block. Therefore, I have to put ALL of my code in TRY and FINALLY blocks.
>
>You see I have a code that creates connection, then creates one Data Reader, then fills up the page from this Data Reader. Then the program creates another Data Reader (reusing still open connection) and fills another stuff on the page from the second Data Reader. Then close connection.
>
>From your replies I gather that I have to do it all in TRY and FINALLY, to get around the scoping problem. Right?
>
>>The problem is with scope - you cannot declare variable in TRY and see it in CATCH. This same apply also for VB.
>>
>>The second problem is with initialization of the variable - you cannot initialize variable in TRY and rely in CATCH that it is initialized, because initialization can also fail. You must initialize it before TRY. This does not apply for VB, because VB internally initializes variables for you.
>>
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.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform