Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Try Catch in Program.cs仅在从visual studio启动时起作用_C#_Visual Studio 2010_Try Catch - Fatal编程技术网

C# Try Catch in Program.cs仅在从visual studio启动时起作用

C# Try Catch in Program.cs仅在从visual studio启动时起作用,c#,visual-studio-2010,try-catch,C#,Visual Studio 2010,Try Catch,我试着为未被监控的事件写一个小事故报告员。在VS中启动我的应用程序时,此功能非常有效。 但是,当我尝试启动.exe时,它只向我显示了一个标准,即有一个来自windows的非预期支出。 不,撞车的不是那个搬运工 这是我在Program.cs中的代码 try { Application.Run(new TestServer()); } catch (Exception e) {

我试着为未被监控的事件写一个小事故报告员。在VS中启动我的应用程序时,此功能非常有效。 但是,当我尝试启动.exe时,它只向我显示了一个标准,即有一个来自windows的非预期支出。 不,撞车的不是那个搬运工

这是我在Program.cs中的代码

        try
        {
            Application.Run(new TestServer());
        }
        catch (Exception e)
        {
            Application.Run(new CrashReporter(e.StackTrace.ToString()));
        }
    }

您是否在64位操作系统上运行?这听起来像是汉斯·帕桑回答的问题


调试会吞掉64位CLR中窗体构造和窗体加载的错误…

您是否在64位操作系统上运行?这听起来像是汉斯·帕桑回答的问题


调试可能会吞噬64位CLR中窗体构造和窗体加载的错误…

您可以处理以下事件,这是处理未处理的应用程序异常的首选方法:

AppDomain.CurrentDomain.UnhandledException += (sender, e) => 
{  
    Application.Run(new CrashReporter(e.StackTrace.ToString())); 
}
Application.Run(new TestServer());

相反,您可以处理以下事件,这是处理未处理的应用程序异常的首选方法:

AppDomain.CurrentDomain.UnhandledException += (sender, e) => 
{  
    Application.Run(new CrashReporter(e.StackTrace.ToString())); 
}
Application.Run(new TestServer());

你确定这东西有用吗?我是说,这个策略以前对你有用吗

我使用并建议这样的方法来全局捕获未处理的异常:

    AppDomain.CurrentDomain.UnhandledException +=
            new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
//then start the main form...
Application.Run(new TestServer());
这是文件

你确定这东西能用吗?我是说,这个策略以前对你有用吗

我使用并建议这样的方法来全局捕获未处理的异常:

    AppDomain.CurrentDomain.UnhandledException +=
            new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
//then start the main form...
Application.Run(new TestServer());
这是文件
是CrashReporter造成的。catch语句中的未捕获异常将导致未捕获异常。你需要在你的捕获中再尝试一次,然后再后退一步。

是CrashReporter造成的。catch语句中的未捕获异常将导致未捕获异常。您需要在catch中进行另一次try/catch和另一次后退。

这是因为您使用了调试器。Winforms检测到此情况并禁用Application.ThreadException的事件处理程序。这很重要,它允许您调试异常。要使catch子句在没有调试器的情况下工作,必须在Run调用之前将以下语句添加到Main方法:

   Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);

现在为AppDomain.Current.UnhandledException编写事件处理程序更有意义,相反,您还将收到工作线程中未处理异常的通知。

这是因为您使用了调试器。Winforms检测到此情况并禁用Application.ThreadException的事件处理程序。这很重要,它允许您调试异常。要使catch子句在没有调试器的情况下工作,必须在Run调用之前将以下语句添加到Main方法:

   Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);

现在为AppDomain.Current.UnhandledException编写事件处理程序更有意义,相反,您还将收到工作线程中未处理异常的通知。

StackTrace已经是一个字符串。你应该通过e.ToString,以便报告实际问题。你能发布CrashReporter类代码吗?你怎么知道它不是CrashReporter?首先尝试添加MessageBox.Showe.ToString,看看它是否显示.StackTrace已经是一个字符串。你应该通过e.ToString,以便报告实际问题。你能发布CrashReporter类代码吗?你怎么知道它不是CrashReporter?首先尝试添加MessageBox.Showe.ToString,看看它是否显示。