Since Response.Redirect cannot be used in a class module, how can I redirect
a user to error.htm from the catch block of a try-catch statement in a class,
say, myClass if an error occurs in myClass?
Thank you,
Nam
public function HandleException ( ex as Exception , p as Page )
// public void HandleException (Exception ex, Page p)
{
p.Response.Write(ex.Message)
'or
p.Response.Redirect(http://www.microsoft.com)
}
on any code behind of the aspx page
try
catch
HandleException( ex , this.Page )
pseudo code, but you get the idea.
"Nam" <N...@discussions.microsoft.com> wrote in message
news:B9066890-C35A-4F48...@microsoft.com...
Simply because you do not know what to do with it.
Let it propagate on top and let Page that calls that module to catch
exception and redirect to "error.htm"
George.
"Nam" <N...@discussions.microsoft.com> wrote in message
news:B9066890-C35A-4F48...@microsoft.com...
I did not mean to suggest to pass the Page p to every routine.
..
Put the "try/catch" in teh aspx.cs (aspx.vb) file....and then when you CATCH
IT THERE, you can implement the method I suggested.
..
But George is correct, let the exception bubble on up.
Bookmark this page as well and refer to it often:
http://blogs.msdn.com/kcwalina/archive/2005/03/16/396787.aspx
"George Ter-Saakov" <gt-...@cardone.com> wrote in message
news:exDY52Ir...@TK2MSFTNGP06.phx.gbl...
Niraj
"Nam" <N...@discussions.microsoft.com> wrote in message
news:B9066890-C35A-4F48...@microsoft.com...
As others have said, it is better to let the exception propulgate.
But if you do want, you can let your class inherit from the Page
class, and then you will have the Respone object available to you.
I totally agree with your assertion. I am new to using classes.
Either I should not have caught the exception in my class or should have
just thrown it as follows and then catch it at the page that calls the method
in my class:
try
{
My code here....
}
catch (Exception ex)
{
throw ex;
}
Thank you for your input.
Best Regards,
Nam