我有一些代码,希望在发生异常时执行它。但是这段代码也可能会产生异常。但我从未见过人们在一个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
}
}
这似乎有点尴尬。它可能存在问题吗?