By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,300 Members | 1,789 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,300 IT Pros & Developers. It's quick & easy.

display exception one label problem

P: n/a
Hi everyone,
I have a piece of code in sales.aspx.vb like this:
Protected WithEvents Message As System.Web.UI.WebControls.Label
Try
...
ChartImage.ImageUrl = "ChartGenerator.aspx?" + DataStr + "&ChartType=" +
drpChartType.SelectedItem.Value.ToLower() + "&Print=" +
printVersion.ToString()
...
Catch e As Exception
Message.Text=e.Message
End Try
It handles exception fine before and after the statement:ChartImage.ImageUrl
....
but it seems not being able to catch the exception in ChartGenerator.aspx.vb
Now I am trying to do is handling the exception in ChartGenerator.aspx.vb.
but don't know what to do. with the following code in ChartGenerator.aspx.vb:
try

catch ex as exception
message.text=ex.message
Response.Redirect("ChartGenerator.aspx")
end try
I tried to let the chartGenerator.aspx display the exception using, but it
seems not working. Instead, it displays timeout message from sale.aspx.
Can you shed a light on me?
--
Betty
Aug 31 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hello Betty,

Welcome.

As for the problem you mentioned, my understanding is you have two separate
page, one page(Sales.aspx) use another page(ChartGenerator.aspx) to return
some dynamic image stream and display the image stream through Image
control. However, you found that you can not quite get the exception info
(occured in ChartGenerator.aspx page) in Sales.aspx , correct?

I think this is due to the ASP.NET page model, each page is only displaying
content/text which is writen into its own response stream. And since
sales.aspx and ChartGenerator.aspx are two separate page, they can not be
aware of any exception occured in the other one's processing stage.

For your scenario, I think your current idea on redirect the response
stream is a workable solution. You can catch the exception in the
ChartGenerator.aspx page and then redirect the current request to another
image stream or better a static image file (which display a error screen
message as picture), or you can directly use response.WriteFile to writeout
that static image file (store in your web application's directory. Thus,
in the sales.aspx, the Image control can still get a valid image binary
stream and display the error screenshot.

e.g.

==========================
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Try
If Request.QueryString("fn") = Nothing Then
Throw New Exception("invalid file name....")
End If
Catch ex As Exception

Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "image/gif"
Response.WriteFile(Server.MapPath("~/images/errorinfo.gif"))
Response.End()
End Try

End Sub
============================

the limitation here is that such a static image file can not display
dynamic exception information(callstack, error message....). If you want to
display the error message through image stream, you'd better create a
custom httphandler which dynamically generate image stream(from given text)
and redirect your ChartGenerator.aspx page to that handler. How do you
think of this?

Here are some good articles mentioned creating httphandler to generate
dynamic image stream in asp.net:

#Build an ASP.NET Thumbnail Image Generator
http://www.eggheadcafe.com/articles/20041104.asp

http://davidhayden.com/blog/dave/arc...9/09/2459.aspx

http://www.microsoft.com/belux/msdn/...et/httphandler.
mspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Sep 1 '06 #2

P: n/a
Steve,
Your explanation is very through and it makes perfect sense to me.
I will read article you provided and try to implement it.
You are one of the best among the microsoft discussion forum supports I have
been joined, including sql server discussion forum.
Good night.
--
Betty
"Steven Cheng[MSFT]" wrote:
Hello Betty,

Welcome.

As for the problem you mentioned, my understanding is you have two separate
page, one page(Sales.aspx) use another page(ChartGenerator.aspx) to return
some dynamic image stream and display the image stream through Image
control. However, you found that you can not quite get the exception info
(occured in ChartGenerator.aspx page) in Sales.aspx , correct?

I think this is due to the ASP.NET page model, each page is only displaying
content/text which is writen into its own response stream. And since
sales.aspx and ChartGenerator.aspx are two separate page, they can not be
aware of any exception occured in the other one's processing stage.

For your scenario, I think your current idea on redirect the response
stream is a workable solution. You can catch the exception in the
ChartGenerator.aspx page and then redirect the current request to another
image stream or better a static image file (which display a error screen
message as picture), or you can directly use response.WriteFile to writeout
that static image file (store in your web application's directory. Thus,
in the sales.aspx, the Image control can still get a valid image binary
stream and display the error screenshot.

e.g.

==========================
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Try
If Request.QueryString("fn") = Nothing Then
Throw New Exception("invalid file name....")
End If
Catch ex As Exception

Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "image/gif"
Response.WriteFile(Server.MapPath("~/images/errorinfo.gif"))
Response.End()
End Try

End Sub
============================

the limitation here is that such a static image file can not display
dynamic exception information(callstack, error message....). If you want to
display the error message through image stream, you'd better create a
custom httphandler which dynamically generate image stream(from given text)
and redirect your ChartGenerator.aspx page to that handler. How do you
think of this?

Here are some good articles mentioned creating httphandler to generate
dynamic image stream in asp.net:

#Build an ASP.NET Thumbnail Image Generator
http://www.eggheadcafe.com/articles/20041104.asp

http://davidhayden.com/blog/dave/arc...9/09/2459.aspx

http://www.microsoft.com/belux/msdn/...et/httphandler.
mspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Sep 1 '06 #3

P: n/a
Thanks for the quick response.

Glad that the suggsetion is helpful to you and appreciate your feedback:)

Good luck!

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 1 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.