GetHtmlErrorMessage()

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I would like to log an error message by calling the
HTTPException.GetHtmlErrorMessage().

For the Exception in the standard ASP.NET pipeline it works. But I'm also
using some asynchron functionality in others threads. When I call there the
GetHtmlErrorMessage() function, I got an empty string

It seems, that the ErrorFormatter in the HttpException is undefined.

Could you explain me, why there's no ErrorMessage?
Who defines or set the ErrorFormatter in the HttpException?

Thanks
Eric
 
Hello Eric,

As for the HttpException, did you manually create an HttpExcetion instance
and throw it in your page code?

Based on my research, HttpException.GetHtmlErrorMessage method does rely on
a certain ErrorFormatter to generate the HtmlErrorMessage. Also, it uses an
internal method "SetFormatter" to assign a formatter, based on my
inspection through the reflector, not any discretionary instance of such
HttpException instance will be assigned a proper ErrorFormatter. One of the
means to set the ErrorFormatter is create a HttpUnhandledException instance
to wrapper the HttpException and in the HttpUnhandledException's
constructor, it will assign a "UnhandledErrorFormatter". e.g.

===================
public partial class Errorhandle_ErrorHandle : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnRaise_Click(object sender, EventArgs e)
{
try
{
GetError();
}
catch (HttpException httpexp)
{
Response.Write("<br/>error<br/>: " +
httpexp.GetHtmlErrorMessage());
}
}

protected void GetError()
{
HttpException httpexp = new HttpException("test httpexp........");
HttpUnhandledException ux = new HttpUnhandledException("wrapper
exp", httpexp);

throw ux;
}
}
========================

BTW, is there any paricular requirement in your scenario that you need to
use the system generated html error message instead of using your own
custom exception and own error message?

Please feel free to post here if there is any other concerns or anything we
can help.


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



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

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.

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



This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks Steven,

I was also digging with the reflector and have found the same like you.

in my case the following stack traces were generated:

Stack Trace of the synchronus exception:

System.Web.HttpUnhandledException: Exception of type
'System.Web.HttpUnhandledException' was thrown. --->
System.ApplicationException: Error in synchronous method.
at SyncErrorTrace.SomeSynchronousMethod() in


And here's the message for the async error message:

System.Web.HttpException: Exception of type 'System.Web.HttpException'
was thrown. ---> System.ApplicationException: Error in asynchronous
method.

Now I see ,why there's no message for the HTTP exception in the async thread.


Yes, it's logging solutions (ELMAH) which would like to store and show the
generated HTML error message in a browser. It's easier to use the genereated
html message.

Thanks
Eric
 
Thanks for your reply Eric,

Glat to hear that you have also figured out this. If you meet any new
problems or anything we can help, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top