捕获由非托管子流程引发的未处理的异常
使用 C# 的 System.Diagnostics.Process 对象,我启动一个非托管 exe,稍后又启动另一个非托管 exe。
第二个 exe 导致了一个未处理的异常,我希望我的应用程序忽略该异常,但似乎无法忽略。
当我启动第一个进程时,我使用了 try/catch 语句,但它似乎没有捕获第二个进程引发的异常。当异常发生时,即时调试器会通知我并停止我的应用程序,直到我手动单击“是”我想要调试或“否”。然后我的申请继续进行。
JIT 调试器没有引发异常的 2ndprocess.exe 的源代码。所以,它没有告诉我例外是什么。我真的不在乎异常是什么,我只是想知道如何捕获它并忽略它,这样我的应用程序就不会被它停止。当异常发生时,工作无论如何都已完成。
谁能提供一些见解?
Using C#'s System.Diagnostics.Process object, I start an unmanaged exe, that later starts yet another unmanaged exe.
The 2nd exe is causing an unhandled-exception that I'd like my application to ignore, but can't seem to.
I'm using a try/catch statement when I start the first process, but it doesn't seem to catch the exception raised by the 2nd process. When the exception occurs, the just-in-time debugger notifies me and halts my application until I manually click "yes" I want to debug or "no". Then my application proceeds.
The JIT debugger doesn't have source code for the 2ndprocess.exe that is throwing the exception. So, it doesn't tell me what the exception is. I don't really care what the exception is, I just want to know how to catch it and ignore it so my application doesn't get halted by it. By the time the exception occurs, the work is done anyway.
Can anyone offer some insight?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该正确处理第二个可执行文件中的异常。您的主程序不会捕获异常,因为它没有抛出异常,而是正在执行异常。
编辑:
您是否有权访问第二个进程(抛出异常的进程)的源代码?您的应用程序不应该崩溃。如果在第二个过程中正确处理了异常情况,那么您的主应用程序中就不会出现此问题。
Edit2:
由于您可以访问源代码(开源),我建议您修复该错误。这将以两种方式帮助您:
1)您的程序最终将运行。
2) 你可以说你为一个开源项目做出了贡献。
而且,作为一项特殊奖励,您可以帮助完成您经常使用的项目。 双赢
You should be properly handling the exception in the second executable. Your main program won't catch the exception because it isn't throwing one, it is executing something that is.
Edit:
Do you have access to the source of the second process (the one throwing the exception)? Your application shouldn't ever just crash. If the exceptional case gets handled correctly in the second process, you won't have this problem in your primary application.
Edit2:
Since you have access to the source (open source) I recommend you fix the bug. This will help you in two ways:
1) Your program will finally work.
2) You can say you contributed to an open source project.
And, as a special bonus, you get to help out a project you use frequently. Win/Win
由于您使用 process.start 来实际启动应用程序,因此该应用程序会创建一个单独的应用程序域。我认为从该应用程序捕获异常是不可能的,因为 JIT 对话框很可能是由于该失败的进程而出现的。
虽然不是解决方案,但您可以停止对话框< /a> 如果需要的话,但这有它自己的问题。
Since you are using process.start to actually launch the application, the application creates a separate application domain. Capturing the exception from that application is not something that I believe will be possible, since more than likely the JIT dialog is coming up due to that failed process.
Although not a solution you could stop the dialog if needed, but that has issues of its own.