对于抛出异常的Java方法,有没有特定的命名约定? [英] Is there a particular naming convention for Java methods that throw exceptions?

查看:219
本文介绍了对于抛出异常的Java方法,有没有特定的命名约定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在区分具有异常的方法(具有类似的签名)中添加类似Ex的后缀,从而引发异常。

I'm tempted to add a suffix like "Ex" to differentiate methods (with similar signatures) that throw Exceptions from those that don't.

这样的惯例?

推荐答案

是的,你把它们命名为不同的方法。

Yes, you name them the same as methods that don't.

不是例外规范吗?

编辑:如果你有类似的方法抛出/不抛出,我推荐 Parse / TryParse pattern( Parse 被操作替换)。 .NET Framework经常使用它( Dictionary< T,K> .TryGetValue Monitor.TryEnter int.TryParse 等)。

If you have similar methods that throw/not throw, I recommend the Parse/TryParse pattern (Parse being replaced by the operation). .NET Framework uses it frequently (Dictionary<T,K>.TryGetValue, Monitor.TryEnter, int.TryParse, etc. etc.).

编辑:编码恐怖:TryParse和异常税

这篇关于对于抛出异常的Java方法,有没有特定的命名约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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