Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Try/Catch Routine Not Working
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00985235
Message ID:
00985466
Views:
36
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform