如何忽略.NET异常 [英] How to ignore the .NET exception

查看:137
本文介绍了如何忽略.NET异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题



Hello代码项目伙伴,

我是在完成图像拼接项目的中期。当我运行我的项目时,我得到一个名为 Non Com visible base class occurrence 的异常。我知道互联网上有很多解决方案,比如



从例外设置中取消选中Non Com可见异常



但我不需要那种解决方案,因为我想将我的项目交付给客户。我不能强迫他们更改例外设置。那么有没有办法在运行时忽略异常。是否有任何代码可以阻止异常破坏代码。



请帮我摆脱这个异常。



我尝试了什么:



我尝试过类似DLLimport的东西可以解决问题,但事实并非如此。请指导我如果DLLimport真的可以用这个做什么........

解决方案

试试
{
//你的代码在这里
}
catch(异常exp)
{
//你可以在这里记录异常或者什么都不做
}
最后
{
// finally块是可选的,但如果你想要
},你可以在发生异常后把你想要的代码放在这里}





这回答了你的问题,但它无法解决你的问题。


正如F-ES Sitecore所说,抓住异常很简单。

但是......这是一个非常糟糕的主意。你得到了例外,因为出了问题,这个过程无法继续。捕获异常是让你的代码从问题中优雅地恢复,它不能解决问题。



我不知道什么是Noncom类,但是如果它抛出异常,那么无论你试图用它做什么都没有用,这可能意味着你的应用程序不会按照用户的意愿去做。



而不是尝试忽略异常,以便您可以发送代码,使用调试器找出导致问题的原因和原因。运输duff代码是一种非常非常好的方式来惹恼客户 - 远比使用24小时的诚实和延迟发货更糟糕,而你修复并完全测试它。


不是最终的解决方案但一些见解:



nonComVisibleBaseClass MDA | Microsoft Docs [ ^ ]



Quote:

取消选中Non Com来自异常设置的可见异常。

这是一个VS选项。因此,您的客户无需更改他们的任何设置。



据我了解,例外(这是一个诊断警报,而不是经典只有在VS内运行应用程序时才会出现异常以便无法捕获。



您是否尝试独立运行(VS外部)?


My Problem

Hello code project mates,
I am in mid of completion of an image stitching project. When I run my project I get an exception called "Non Com visible base class occurred". I know that there are lot of solutions around the internet on this like

"Uncheck the Non Com visible exception from the exception settings ".

But I don't need that kind of solution because I wanna deliver my project to client. I can't force them to change exception settings. So is there a way to ignore the exception at runtime. Is there any code to stop the exception from breaking the code.

Please help me to get rid of this exception.

What I have tried:

I tried something like DLLimport which can solve the problem but it doesn't. Please guide me what to do if the DLLimport really works with this........

解决方案

try
{
    // your code here
}
catch(Exception exp)
{
    // you can log the exception here or simply do nothing
}
finally
{
    // the finally block is optional but you can put code you want to happen here after an exception occurs if you want
}



That answers your question but it isn't going to solve your problem.


As F-ES Sitecore says, catching the exception is simple.
But ... it's a very bad idea. You get the exception because something is wrong, and the process can't continue. Catching the exception is there to let your code recover gracefully from a problem, it doesn't solve the problem.

I have no idea what a Noncom class is, but if it throws an exception then whatever you were trying to do with it has not worked, and that probably means that your app is not going to do what the user wants.

Instead of trying to ignore the exception so you can ship code, use the debugger to find out what is causing the problem and why. Shipping duff code is a very, very good way to annoy clients - far, far worse than being honest and delaying shipment for 24 hours while you fix and fully test it.


Not a final solution but some insights:

nonComVisibleBaseClass MDA | Microsoft Docs[^]

Quote:

Uncheck the Non Com visible exception from the exception settings.

That is a VS option. So your clients do not have to change any settings on their side.

As far as I understood it, the exception (which is a diagnostic alert and not a "classic" exception so that it can't be catched) is only raised when running the appliction from within VS.

Have you tried running it standalone (outside VS)?


这篇关于如何忽略.NET异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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