Questions tagged «user-interaction»

6
我应该如何处理无效的用户输入?
我考虑这个问题已有一段时间了,我很想征询其他开发人员的意见。 我倾向于具有非常防御性的编程风格。我典型的块或方法如下所示: T foo(par1, par2, par3, ...) { // Check that all parameters are correct, return undefined (null) // or throw exception if this is not the case. // Compute and (possibly) return result. } 另外,在计算过程中,我在取消引用所有指针之前先检查它们。我的想法是,如果存在某些错误,并且某些地方应该出现一些NULL指针,则我的程序应该很好地处理此问题,并且只是拒绝继续进行计算。当然,它可以通过日志或其他机制中的错误消息来通知问题。 换句话说,我的方法是 if all input is OK --> compute result else --> do not compute …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.