Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Variable scope and try and catch
Message
De
17/09/2003 11:37:18
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00829818
Message ID:
00829930
Vues:
21
This message has been marked as the solution to the initial question of the thread.
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.

The same applies for FINALLY. Here is C# workaround:
SqlDataReader dr = null;  //INITIALIZATION

try
{
  ...
  dr = sqlcmd.ExecuteReader();
  ...
}
catch InvalidOperationException ex  //Sample exception handling
{
  ...
}
finally
{
  if(dr != null)
    dr.Close();
}

Plamen Ivanov
MCSD .NET Early Achiever and MCAD .NET Charter Member (VB .NET/SQL Server 2000)
MCSD (VB 6.0/SQL Server 2000)

VB (.NET) - what other language do you need in the whole Universe?...

Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform