Another way that listeners can make trouble for unwary event sources is throwing an unchecked exception.
对于不小心的事件源,侦听器会造成麻烦的另一个方式是:抛出未检测的异常。
Instead of throwing an unchecked exception with a call to the add method, you just get false returned by offer .
它不是对调用add方法抛出一个unchecked异常,而只是得到由offer返回的false。
For this purpose I'll define ArgumentErrorException as an unchecked exception to be thrown if one of these errors occurs.
出于这个目的,我将定义ArgumentErrorException作为一个未经检查的异常,如果出现了某个这一类的错误,就将抛出这个异常。
For instance, adding elements to a Queue could be done with the add method of Collection, throwing an unchecked exception on failure.
例如,向Queue添加元素可以用Collection的add方法来实现,它在失败时会抛出未检测异常。
You might even want to automatically unregister a listener that throws an unchecked exception; after all, this is evidence that the listener is broken.
对于抛出未检测异常的侦听器,您可能想自动对它取消登记,毕竟,抛出未检测异常就证明侦听器坏掉了。
If the caller won't be able to handle the exception in a meaningful way, consider throwing an unchecked (run-time) exception.
如果调用者不能以有意义的方式处理这个异常,那么考虑抛出一个未检查的(运行时)异常。
Also note that Objectify's exceptions are unchecked - which means I don't have to worry about catching a bunch of exception types.
还要注意,Objectify的异常未经检查—这表示我无需担心捕捉到很多exception类型。
Note that if we do want to recover from an unchecked data access exception, we can still.
注意如果我们想从一个未检查的数据访问异常恢复,我们同样可以。
Note that if we do want to recover from an unchecked data access exception, we can still.
注意如果我们想从一个未检查的数据访问异常恢复,我们同样可以。
应用推荐