在谈到尝试catch语句 [英] Commenting try catch statements
本文介绍了在谈到尝试catch语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是合适的地方来解释一个try-catch语句错误处理?好像你可以把解释性意见在try块的开始处或catch块。
//可能注释位置1
试
{
//真正的代码
}
//可以这么评论位置2
抓
{
//可以这么评论位置3
//错误处理代码
}
解决方案
我通常会做以下。如果只有一个被处理的异常,我通常不打扰,因为它应该是自我描述。
试
{
实际代码//抛出SomeException
实际代码//抛出SomeOtherException
}
赶上(SomeException SE)
{
//解释你的错误处理的选择,如果不是很明显
}
赶上(SomeOtherException SOE)
{
//解释你的错误处理的选择,如果不是很明显
}
What is the proper place to explain error handling in a try-catch statement? It seems like you could put explanatory comments at either the beginning of the try block or the catch block.
// Possible comment location 1
try
{
// real code
}
// Possible comment location 2
catch
{
// Possible comment location 3
// Error handling code
}
解决方案
I usually do the following. If there's only one exception being handled, I usually don't bother since it should be self-documenting.
try
{
real code // throws SomeException
real code // throws SomeOtherException
}
catch(SomeException se)
{
// explain your error handling choice if it's not obvious
}
catch(SomeOtherException soe)
{
// explain your error handling choice if it's not obvious
}
这篇关于在谈到尝试catch语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文