468,134 Members | 1,273 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,134 developers. It's quick & easy.

sending error message from a class module

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

Jun 27 '08 #1
6 1037
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.

"Nam" <Na*@discussions.microsoft.comwrote in message
news:B9**********************************@microsof t.com...
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

Jun 27 '08 #2
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" <Na*@discussions.microsoft.comwrote in message
news:B9**********************************@microsof t.com...
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

Jun 27 '08 #3
Correct.

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/archi...16/396787.aspx

"George Ter-Saakov" <gt****@cardone.comwrote in message
news:ex**************@TK2MSFTNGP06.phx.gbl...
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" <Na*@discussions.microsoft.comwrote in message
news:B9**********************************@microsof t.com...
>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


Jun 27 '08 #4
I suppose you can use httpcontext.currentcontext. library.

Niraj
"Nam" <Na*@discussions.microsoft.comwrote in message
news:B9**********************************@microsof t.com...
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

Jun 27 '08 #5
Nam wrote:
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.
Jun 27 '08 #6
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
"George Ter-Saakov" wrote:
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" <Na*@discussions.microsoft.comwrote in message
news:B9**********************************@microsof t.com...
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


Jul 24 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by praba kar | last post: by
reply views Thread by praba kar | last post: by
17 posts views Thread by Steve Jorgensen | last post: by
6 posts views Thread by Peter Frost | last post: by
11 posts views Thread by ColinWard | last post: by
7 posts views Thread by bleachie | last post: by
31 posts views Thread by happyse27 | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.