我在我的.net应用程序中使用COM对象(MODI).我调用的方法抛出一个System.AccessViolationException,它被Visual Studio拦截.奇怪的是我在try catch中包含了我的调用,它包含AccessViolationException,COMException和其他所有东西的处理程序,但是当Visual Studio(2010)拦截AccessViolationException时,调试器会中断方法调用(doc.OCR),如果我单步执行,它将继续到下一行,而不是进入catch块.另外,如果我在visual studio外部运行,我的应用程序崩溃了.如何处理COM对象中引发的此异常?
MODI.Document doc = new MODI.Document();
try
{
doc.Create(sFileName);
try
{
doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false);
sText = doc.Images[0].Layout.Text;
}
catch (System.AccessViolationException ex)
{
//MODI seems to get access violations for some reason, but is still able to return the OCR text.
sText = doc.Images[0].Layout.Text;
}
catch (System.Runtime.InteropServices.COMException ex)
{
//if no text exists, the engine throws an exception.
sText = "";
}
catch
{
sText = "";
}
if (sText != null)
{
sText = sText.Trim();
} …
Run Code Online (Sandbox Code Playgroud) Visual Studio曾经有一个特定的复选框"Break on Un-handling exception".在2015年,这已被删除(或移动到我找不到的地方).因此,如果我未能提供用户级异常处理程序,那么现在我的转换项目不再中断.我不想打破所有"抛出异常",因为我处理特定的异常.就在我无法提供特定处理程序的地方.
现在我的代码只退出当前程序并继续在下一个调用堆栈位置执行,而不是好.
任何人都知道如何在Visual Studio 2015中获得此功能?我昨天刚升级到社区版.
c# exception-handling unhandled-exception visual-studio-2015