Response.Redirect Where to put it?

H

Henry

Hello,

I have a question about ASP.NET process. In this case:

Try
'SOME CODE

Response.Redirect("some_asp_page.aspx")
Catch obj_Exception as Exception
Throw obj_Exception
Finally
If Not (obj_Conn Is Nothing) Then obj_Conn.Dispose()
End Try

I wonder if ASP.NET reaches the finally part of the code or does it redirect
and neever reaches the finally statement?
Or should write something like this?

Try
'SOME CODE

Catch obj_Exception as Exception
Throw obj_Exception
Finally
If Not (obj_Conn Is Nothing) Then obj_Conn.Dispose()
Response.Redirect("some_asp_page.aspx")
End Try

Which one should I use?

Thanks in advance?

Henry
 
K

Karl

The finally code will always get executed, so the first case is fine.
Interstingly enought your catch code will also get reached 100% of the time.
Response.Redirect throws a ThreadAbordException, so your code in the try{}
block will always throw an exception, which will be caught and rethrown by
your catch, and your finally will clean up. Since the thread is aborted,
everything works fine..so it's ok....but it is pretty interesting :)

On a side note, you probably don't want to rethrow the exception, consider
replace your catch code with:

Catch obj_Exception as Exception
Throw

which, instead of throwing an exception of type Exception with an
innerException of the actual type, will actually throw the original
exception with all the juicy information readily available. Check out:
http://dotnetguy.techieswithcats.com/archives/004118.shtml for a better
explenation (if you are interested)

Karl
 

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,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top