且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何处理C#中的异常?

更新时间:2023-08-23 14:39:10

Quote:

需要警告任何人都可以意外地点击右键。我想,流产是愚蠢的。我该如何实现呢?请帮忙。

A warning is needed as anyone can right click by accident. So aborting is stupidity, I guess. How shall I implement this? Please help.

我们不能 - 你要做的第一件事是使用调试器来确切地找出数组索引中的内容,以及它为什么到达那里。在抛出异常的行上放置一个断点,并在变量被击中时查看它们。想想你期望在那里做什么,以及你实际得到了什么。他们为什么不同?该值是如何实现的?



如果是用户错误,请检查它,并使用MessageBox显示相应的错误。如果不是,那么就开始追踪价值是如何到达那里的,并找出你需要做些什么来防止再次发生。



对不起,但是我们不能为你做到这一点!

We can't - the first thing you have to do is use the debugger to find out exactly what is in the array index, and why it got there. Put a breakpoint on the line throwing the exception, and look at the variables when it gets hit. Think about what you expected to be there, and what you actually got. Why are they different? How did that value get there?

If it's a user error, then check for it, and display an appropriate error using MessageBox. If it isn't, then start back tracking how the value got there, and find out what you need to do to prevent that from happening again.

Sorry, but we can't do that for you!