473,396 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1204
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: praba kar | last post by:
Dear All, In Php we can do all the mailing operations like sending a text as a message, adding attachment to a mail, adding additional headers and so on using Mail_mime class. I want to know...
0
by: praba kar | last post by:
Dear All, I have doubt regarding mail sending smtplib module. The below code is I used to send a mail. ########################################## import email.Message import email.Utils...
4
by: Chuck Ritzke | last post by:
I keep asking myself this question as I write class modules. What's the best/smartest/most efficient way to send a large object back and forth to a class module? For example, say I have a data...
17
by: Steve Jorgensen | last post by:
If you've ever employed custom error numbers and messages in you programs, you've probably ended up with code similar to what I've ended up with in the past something like... <code> public...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
11
by: ColinWard | last post by:
Hi. I have the following code in a module which sends email via Outlook. Option Compare Database Option Explicit ' Declare module level variables Dim mOutlookApp As Outlook.Application Dim...
7
by: bleachie | last post by:
Hey, I just need some help, my form seems to not send me all of the 'guestNames' and 'guestEmails' forms. i use this function to add more guestnames and guestemail fields based on the number of...
11
by: minishilpi | last post by:
I have a question - I have this code below to send an email and I have referenced the Microsoft CDO Library 2000. It doesn't throw any exception in the console window. It goes throughout the code...
31
by: happyse27 | last post by:
Hi All, I am trying for weeks how to send email from windows pc, which from my gmail account to my hotmail account. Using net::smtp module sending email failed,Kindly assist. (for the item d it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.