例外的基本问题 [英] basic question on exceptions

查看:144
本文介绍了例外的基本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当方法无法处理的异常发生时- 程序终止并显示错误号?错误在哪里 错误的数量和信息来自何处?应该 程序员在编码时有一个想法可能是什么样的异常 发生.如果是这样,为什么不确保不会发生异常.

when an exception occurs that a method is unable to handle - does the program terminate and show the error number ? where does the error number and information about the error come from ? should the programmer while coding have an idea what kind of exception might occur. if so why does''nt he ensure that exception does not occur .

推荐答案

好问题.

我的观点是,开发人员应在他们正在工作的层上处理他们知道(或负责)的异常.如果他们创建了任何新的异常,则他们负责在文档中传递这些数据,以便消费者可以正确地处理它们.

My opinion is that the developer should be handling the exceptions that they are aware of (and perhaps responsible for) at the layer they are working. If they create any new exceptions then they are responsible for passing that data along in their docs so the consumer can handle them properly.

是的,开发人员应该始终对可能发生的异常类型有所了解,但这并不意味着他们必须处理所有异常.但是,他们应该能够接受他们,并且至少在他们发生时不会死亡.这真的取决于(如何明确?:))取决于您正在工作的层.

Yes, the developer should always have some idea about what kind of exceptions can occur, but that doe snot mean that they HAVE to handle them ALL. They should however be able to accept them and at very least not die when they happen. It all really depends (hows that for being clear? :) ) on the layer you are working.


这篇关于例外的基本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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