捕获另一个进程未处理的异常 [英] catch another process unhandled exception

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

问题描述

我想知道我是否可以捕获由我开始使用 Process.Start(...) 的另一个进程抛出的未处理的异常

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

我知道我可以使用这个link ,但我想要的是捕获通常由 .net 环境的 Just In Time 调试器捕获的错误,带有接下来的这些话:您的应用程序中发生了未处理的异常.如果您继续,应用程序将忽略此错误并尝试继续.如果您单击退出,应用程序将立即关闭......"然后是异常消息和继续"和退出"按钮.

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)调用 Program 类的 Main 方法到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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆