问题描述
所以我想现在如果可能的.NET语言来忽略错误,而不使用try抓建设?
So I want to now if that possible for .NET languages to ignore error without using try catch construction ?
我可以忽略与#nowarring 40例如交战,我可以忽略错误?
I can ignore warring with #nowarring 40 for example, can I ignore error ?
为什么我需要它?
只是想叫这个路系统暂停
simply wanted to call system pause with this way
open System.Runtime.InteropServices
[<DllImport(@"msvcrt.dll")>]
extern void system(string str)
system "pause"
但得到错误信息
but got Error message
不平衡的堆栈。这可能是 因为托管的PInvoke签名 不匹配的非托管目标 签名。确保通话 会议及参数 的PInvoke签名与目标 非托管签名。
所以,我不在乎,它的工作原理。但是,我可以忽略这个错误?没有做怪异的东西,这样的:
So I don't care, it works. But can I just ignore this error ? without doing weird stuff like that :
try (system "pause") catch |_->()
好吧,我解决我的问题,加入CallingConvention = CallingConvention.Cdecl,但问题是关于跳过异常是什么,所以我还是不知道,如果我能做到这一点。
Ok , I solved my problem by adding CallingConvention=CallingConvention.Cdecl, but what the question was about skipping exceptions, so and I still don't know if I can do it.
所以,也许我要告诉一些真正的理由不被向下投硬 - 有时它的事项的程序与硬错误的职业,甚至住,但即使有时你并不需要赶上他们。你只需要忽略他们...
So maybe I need to tell some real reason to not be down-voted hard - sometimes it's matters for program to live even with hard errors occupations, but even sometimes you don't need to catch them. You need just ignore them...
题外话:关于使用INT的空白,而不是证明图像:
off topic : proof image about using void instead of int :
推荐答案
- 在C#中,我不认为有办法忽略所有的异常,除了
的try ... catch
- 在VB.Net有一个办法忽略所有异常:
VB.Net code:
VB.Net code:
On Error Resume Next '' all exceptions after this point will be ignored
System("pause")
不过,这是一个危险的功能。例外规定,只有在被忽略
But it's a dangerous feature. Exceptions should only be ignored if
- 您绝对有信心,你知道他们为什么发生
- 您绝对有信心可以安全地忽略它们。
在我的愚见,并没有冒犯的意思,从你的问题,我不认为你明白为什么发生错误或者为什么它是危险的忽略它。
In my humble opinion, and with no offence meant, from your question I don't think you understand why the error has occurred or why it is dangerous to ignore it.
这篇关于我可以忽略的错误,而无需使用尝试捕捉()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!