简体   繁体   English

跟踪未处理的asp.net异常

[英]Tracking down unhandled asp.net exception

We have an asp.net web application and for one of our users, an exception is thrown on a specific page when they click on a button. 我们有一个asp.net Web应用程序,对于我们的一位用户,当他们单击按钮时,会在特定页面上引发异常。 I have not been able to recreate this issue, but the system is logging an exception when the client gets the exception. 我无法重新创建此问题,但是当客户端获取异常时,系统正在记录异常。 The problem is, I don't know where the exception is being generated. 问题是,我不知道在哪里生成异常。 When we log an exception, we call the ToString() method on the exception to get the stack trace. 当我们记录异常时,我们对异常调用ToString()方法以获取堆栈跟踪。 It's a parsing error, but I can't tell where it's coming from. 这是一个解析错误,但我无法确定它的来源。 Here's the exception as we logged it: 这是我们记录的例外:

System.FormatException: Input string was not in a correct format. System.FormatException:输入字符串的格式不正确。
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) 在System.Number.StringToNumber处(字符串str,NumberStyles选项,NumberBuffer&数字,NumberFormatInfo信息,布尔值parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.ComponentModel.Int32Converter.FromString(String value, NumberFormatInfo formatInfo) at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) 在System.Number.ParseInt32(String s,NumberStyles样式,NumberFormatInfo信息)在System.ComponentModel.Int32Converter.FromString(字符串值,NumberFormatInfo formatInfo)在System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext上下文,CultureInfo文化,对象值)

I assume this is being logged by the following code in the Global.asax 我认为这是由Global.asax中的以下代码记录的

void Application_Error(object sender, EventArgs e) 
    {
        // Code that runs when an unhandled error occurs
        if (Server.GetLastError() != null)
        {
            Exception objErr = Server.GetLastError().GetBaseException();
            objErr.WriteExceptionLog();
        }
    }

However, I don't know where this code is getting called from or how to find out. 但是,我不知道此代码从何处调用或如何找到。 Any ideas on where I can look or if I need to do something different when I'm logging the exception? 关于在哪里可以看到我的想法,或者在记录异常时是否需要做一些不同的事情?

Here you go: 干得好:

void Application_Error(object sender, EventArgs e) 
{
    // Code that runs when an unhandled error occurs
    if (Server.GetLastError() != null)
    {
        Exception err = Server.GetLastError().InnerException;

        // handle error here

        Server.ClearError();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM