将逻辑错误转换为运行时错误 [英] convert logical errors to runtime errors

查看:77
本文介绍了将逻辑错误转换为运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Visual C#中将逻辑错误转换为运行时错误?

how can i convert logical errors to run time errors in visual C#?

推荐答案

当您说错误时,您是指异常吗?

您可以在C#中使用throw关键字引发类似以下的异常:
When you say error do you mean exceptions?

You can use the throw keyword in C# to throw an exception like:
throw new System.ArgumentException("Parameter cannot be null");



您也可以从System.Exception派生出自己的内容.



you can also derive from System.Exception to create your own.


您知道逻辑错误"是什么意思吗?

让我举一个例子,然后请我解释一下,任何人都可以将逻辑错误更改为运行时错误.

您的应用程序必须在列表的偶数索引处添加数字并给出平均值.而不是偶数索引,您会错误地使用奇数索引.平均值与平均值相同.每一个小的语法都是完美的,代码可以完美地编译而不会出现任何错误/警告,并执行以提供结果.任何人都无法猜测该程序做错了什么(甚至连人都不看结果).现在,您的代码如何处理它并单独触发一个警报,提示存在逻辑错误,需要将其转换为某些异常或运行时错误?
Do you know what a ''logical error'' means?

Let me put up an example and then please explain me that how can ANYONE change the logical error into runtime error.

Your application has to add numbers at even indexes from a list and give an average. Instead of going even indexes you by mistake go odd indexes. Average comes in the same range as even would had. Every little syntax is perfect and code compiles perfectly without any error/warning and executes to give you the result. Anyone cannot even guess that the program is doing something wrong (Not even human looking at the result). Now, how can your code handle it and trigger an alert all by itself that there is a logical mistake and it needs to be converted to some exception or runtime error?


您好,
当我们谈论.NET Framework时,逻辑错误实际上并不是错误.在这种情况下,您的Web或Window应用程序将运行并且代码将执行,但结果将不是您所期望的.在您可能知道计算机总是执行您要完成的事情上,而不是您想要做的事情上.而且我不确定用于找出应用程序中逻辑错误的工具.
最好的问候.
hello there
Logical errors are actually are not errors when we talk about .NET Framework.as in this case your web or Window application run and the code executes but result will be not what you expected. also on thing you may know computer always do what you tell it to be done, not what you wanted. and i am not sure about the tools to find out the logical error in application.
best regards.


这篇关于将逻辑错误转换为运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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