sending error message from a class module

  • Thread starter Thread starter Nam
  • Start date Start date
N

Nam

Using Response.Redirect(“error.htmâ€) in the catch block of a try-catch
statement, I am redirecting a page to a generic page if an error occurs in
code-behind of the page.

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
 
Pass the Page in...as a parameter


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.
 
If you have problem like that it means that you were not suppose to catch
Exception in the module...

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 said:
Using Response.Redirect(“error.htm”) in the catch block of a try-catch
statement, I am redirecting a page to a generic page if an error occurs in
code-behind of the page.

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

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.
 
George,

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
 
Back
Top