Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Try/Catch Routine Not Working
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00985235
Message ID:
00985466
Vues:
37
Hi,
>>
private string TestMethod()
{
	try
	{
		throw new Exception("Go Pack Go");
		return "in try";
	}
	catch (Exception Ex)
	{
		MessageBox.Show(Ex.ToString());
		return "in catch";
	}
}
I can see that, in this case, the 'return' will never execute (incidently VB.NET doesn't flag this up). But I was under the impression that a 'return' would never work in a try block (help states "You cannot branch out of a TRY block, into a CATCH block, or into or out of a FINALLY block"). However it looks like I was wrong:
Private Sub Test()
Try
  Throw New Exception("Outer")
  Catch ex as Exception
    Try
      Return
    Finally
      MsgBox("Inner Finally")
    End Try
    MsgBox("Back to Outer")
  Finally
    MsgBox("Outer Finally")
EndTry
MsgBox("Normal Return")
End Sub
This VB code runs both Finally blocks then executes the Return (ie "Back to Outer" and "Normal Return" don't execute). Oh well, live and learn....
Regards,
Viv
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform