我有一些代码想要在发生异常时执行。但该代码也可能生成异常。但我从未见过有人在另一个 try/catch 中执行 try/catch。
我的做法很糟糕,也许有更好的方法:
Uri uri = Uri.parse("some url");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
try
{
startActivity(intent);
}
catch (ActivityNotFoundException anfe)
{
// Make some alert to me
// Now try to redirect them to the web version:
Uri weburi = Uri.parse("some url");
try
{
Intent webintent = new Intent(Intent.ACTION_VIEW, weburi);
startActivity(webintent);
}
catch ( Exception e )
{
// Make some alert to me
}
}
好像有点别扭。是不是有什么问题?
没关系,但如果您的异常处理逻辑那么复杂,您可能会考虑将其分解为自己的函数。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)