예외가 발생하면 실행할 코드가 있습니다. 그러나이 코드는 예외를 생성 할 수도 있습니다. 하지만 나는 사람들이 다른 try/catch 내부에서 try/catch를하는 것을 본 적이 없습니다.자바 - 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
}
}
그것은 어색한의 종류를 보인다는. 거기에 뭔가 잘못되었을 수 있습니까?
독자적인 방법으로 catch 블록에 코드를 삽입하는 것이 좋습니다. –
@HunterMcMillen 좋은 지적. :) – GeekedOut