问题描述
我想知道我是否可以捕获另一个进程抛出的未处理的异常,我开始使用Process.Start(...)我知道我可以使用这个,但是我想要的是捕获通常由the.net环境的Just In Time调试器捕获的错误,窗口包含以下单词:
您的应用程序中发生了未处理的异常,如果继续,应用程序将忽略此错误并尝试继续。如果单击退出,应用程序将立即关闭....
其后是异常消息和Cont
提前感谢
p>如果您正在调用.Net可执行程序集,可以加载它(并且自己承担风险:D)将Program类的Main方法调用到try_catch语句中:
Assembly assembly = Assembly.LoadFrom(ErroneusApp.exe);
Type [] types = assembly.GetTypes();
foreach(类型t中的类型)
{
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;
}
}
但请注意您正在介绍的安全风险那个。
I wish to know if i can catch the unhandled exceptions thrown by another process which I started using the Process.Start(...)
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.
Thanks in advance.
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.
这篇关于抓住另一个进程未处理的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!