赶上另一个进程未处理的异常

赶上另一个进程未处理的异常

本文介绍了赶上另一个进程未处理的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果我能赶上另一个过程,我开始使用的Process.Start(...)抛出的未处理异常

I wish to know if i can catch the unhandled exceptions thrown by another process which I started using the Process.Start(...)

我知道我可以使用捕捉standered错误此link ,但我要的是赶上通常由the.net环境,用下面的话窗口仅在时间调试器所捕获的错误:
未处理的异常发生在您的应用程序。如果继续,应用程序将忽略此错误并尝试继续操作。如果单击退出,应用程序将被立即关闭......
然后随后是异常消息和一个继续和退出按钮

I know i can catch the standered error using this link , but what I want is to catch the error that are usually caught by the Just In Time debugger of the.net environment, the window with the following words:"An unhandled exception has occurred in your application . If you Continue, the application will ignore this error and attempt to continue . If you click Quit, the application will be shut down immediately ...."Which is then followed by the exception message and a "Continue" and "Quit" button.

先谢谢了。

推荐答案

如果你打电话给一个.net可执行程序集可以加载并(在您自己的风险:D)调用程序类的主要方法为一个try_catch语句:

If you are calling to a .Net executable assembly you can load it and (at your own risk :D ) call to the Main method of the Program class into a try_catch statement:

Assembly assembly = Assembly.LoadFrom("ErroneusApp.exe");
Type[] types= assembly.GetTypes();
foreach (Type t in types)
{
 MethodInfo method = t.GetMethod("Main",
     BindingFlags.Static | BindingFlags.NonPublic);
 if (method != null)
 {
    try
    {
        method.Invoke(null, null);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
    break;
 }
}

但要注意的安全风险你介绍这样做。

But be aware of the security risks you are introducing doing that.

这篇关于赶上另一个进程未处理的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 09:08