Try Catch and Finally

A

Alfredo

Hi,

I have question, i debug this code:

try
'Some operations
catch
Response.Redirect("Page 1")
finally
Response.Redirect("Page 2")
end try

I am getting an error but always Page 2 is loaded. Why?

Thanks,

Alfredo Barrientos
 
M

Marina

Because the Finally block always executes no matter if the try part
succeeded or not.
 
C

Curt_C [MVP]

Alfredo said:
Hi,

I have question, i debug this code:

try
'Some operations
catch
Response.Redirect("Page 1")
finally
Response.Redirect("Page 2")
end try

I am getting an error but always Page 2 is loaded. Why?

Thanks,

Alfredo Barrientos

try a throw or break, but the idea is that the FINALLY will always fire.
Also, look at the Response.Redirect() it has some extra props to stop
execution, perhaps that will work for you.
 
G

Grant Merwitz

The way the Catch statement works is:

1) TRY run the code in the Try part

2) If an exception occurs, run code in the Catch Part.

3) FINALLY , run code in the Finally part.

So no matter what happens, that finally will always run.
 
M

Marc Robitaille

Try
'Some operations

Response.Redirect("Page 2")

Catch
Response.Redirect("Page 1")

End Try()
 
K

Kevin Spencer

What they all said.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Everybody picks their nose,
But some people are better at hiding it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top