application crash in try catch

G

Guest

I am using try catch in my application. If I use response.redirect in try catch and suppose any error occur in response.redirect line , that error is not catched but crash my application

For exampl

private sub subRedirectTo(
tr
response.redirect("wrongfilename"

catch ex as exceptio

throw ex

end tr

end su

In above example suppose the URL name is wrong or file name is wrong then that exception is not handled in
catch part but application get crash on response.redirect line

How to solve this proble

Thanks and regard
Nileshw
 
E

Eric Lawrence [MSFT]

Can you elaborate on what you mean when you say the "application get crash"
on the response redirect line? What exactly is happening?

--
Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.

Nileshw said:
I am using try catch in my application. If I use response.redirect in try
catch and suppose any error occur in response.redirect line , that error is
not catched but crash my application.
For example

private sub subRedirectTo()
try
response.redirect("wrongfilename")

catch ex as exception

throw ex

end try

end sub

In above example suppose the URL name is wrong or file
name is wrong then that exception is not handled in
 
S

Sorin Dolha [MCSD .NET]

Nileshw,

Redirecting to a web page that doesn't exist is not an exception, from the code point of view. The code managed to do the right job: it sent a request to the client browser to navigate to the page URL specified as the parameter for the Redirect() method. Therefore, no exception is thrown and no exception is to be caught on the server side code.

The problem will occur only later, when the client browser finds out that the requested URL is not found or that there was a problem when loading the new page from its web server (which may be another web server, from another part of the world). The client then displays a message describing the problem - but the server is now away from the situation.

If you redirect to a page existing in the same web application and want to generate an exception from the server side code, try to look for the required page (for example, using File.Exists(Server.MapPath("yourpage")) and if it doesn't exist, throw an exception yourself, from code (throw new Exception("yourpage was not found")), before redirecting.

I hope it helped,

--
Sorin Dolha [MCAD, MCSD .NET]

I am using try catch in my application. If I use response.redirect in try catch and suppose any error occur in response.redirect line , that error is not catched but crash my application.

For example

private sub subRedirectTo()
try
response.redirect("wrongfilename")

catch ex as exception

throw ex

end try

end sub

In above example suppose the URL name is wrong or file name is wrong then that exception is not handled in
catch part but application get crash on response.redirect line.

How to solve this problem

Thanks and regards
Nileshw
 
A

Anatoly

For your information:
If you do redirect inside try block exception thrown and catch block executes.

Nileshw,

Redirecting to a web page that doesn't exist is not an exception, from the code point of view. The code managed to do the right job: it sent a request to the client browser to navigate to the page URL specified as the parameter for the Redirect() method. Therefore, no exception is thrown and no exception is to be caught on the server side code.

The problem will occur only later, when the client browser finds out that the requested URL is not found or that there was a problem when loading the new page from its web server (which may be another web server, from another part of the world). The client then displays a message describing the problem - but the server is now away from the situation.

If you redirect to a page existing in the same web application and want to generate an exception from the server side code, try to look for the required page (for example, using File.Exists(Server.MapPath("yourpage")) and if it doesn't exist, throw an exception yourself, from code (throw new Exception("yourpage was not found")), before redirecting.

I hope it helped,

--
Sorin Dolha [MCAD, MCSD .NET]

I am using try catch in my application. If I use response.redirect in try catch and suppose any error occur in response.redirect line , that error is not catched but crash my application.

For example

private sub subRedirectTo()
try
response.redirect("wrongfilename")

catch ex as exception

throw ex

end try

end sub

In above example suppose the URL name is wrong or file name is wrong then that exception is not handled in
catch part but application get crash on response.redirect line.

How to solve this problem

Thanks and regards
Nileshw
 
S

Sorin Dolha [MCSD .NET]

Nobody said they don't. But if the redirect is to an incorrect URL no exception is thrown (no exception is generated by the Redirect statement, even if the URL is incorrect).

--
Sorin Dolha [MCAD, MCSD .NET]
For your information:
If you do redirect inside try block exception thrown and catch block executes.

Nileshw,

Redirecting to a web page that doesn't exist is not an exception, from the code point of view. The code managed to do the right job: it sent a request to the client browser to navigate to the page URL specified as the parameter for the Redirect() method. Therefore, no exception is thrown and no exception is to be caught on the server side code.

The problem will occur only later, when the client browser finds out that the requested URL is not found or that there was a problem when loading the new page from its web server (which may be another web server, from another part of the world). The client then displays a message describing the problem - but the server is now away from the situation.

If you redirect to a page existing in the same web application and want to generate an exception from the server side code, try to look for the required page (for example, using File.Exists(Server.MapPath("yourpage")) and if it doesn't exist, throw an exception yourself, from code (throw new Exception("yourpage was not found")), before redirecting.

I hope it helped,

--
Sorin Dolha [MCAD, MCSD .NET]

I am using try catch in my application. If I use response.redirect in try catch and suppose any error occur in response.redirect line , that error is not catched but crash my application.

For example

private sub subRedirectTo()
try
response.redirect("wrongfilename")

catch ex as exception

throw ex

end try

end sub

In above example suppose the URL name is wrong or file name is wrong then that exception is not handled in
catch part but application get crash on response.redirect line.

How to solve this problem

Thanks and regards
Nileshw
 

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,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top