Javadoc和RuntimeException [英] Javadoc and RuntimeException

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

问题描述

我很好奇我是否应该在方法签名后添加抛出ExceptionClass 。(ExceptionClass扩展了RuntimeException)

I am curious about if I should add throws ExceptionClass or not after the method's signature.(ExceptionClass extends RuntimeException)

例如:

public void foo() // throws ExceptionClass
{
    // ...
    throw new ExceptionClass("");
}


推荐答案

理想情况下,您不需要在方法的throws子句中添加运行时异常。由于您希望此方法的使用者知道此方法可能引发异常的机会,因此我可以使用javadoc之一。以下是应如何使用的示例:

Ideally you don't need to add runtime exception in method's throws clause. Since you want the consumer of this method to be aware of chances that this method may throw exception , i would say use javadoc either. Below is example of how you should use :

/**
 * 
 * @throws ExceptionClass
 */
public void foo()
{
    // ...
    throw new ExceptionClass("");
}

这篇关于Javadoc和RuntimeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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