Tengo un código que deseo ejecutar si ocurre una excepción. Pero ese código también puede generar una excepción. Pero nunca he visto a la gente intentar/atrapar dentro de otro try/catch.Java: ¿es una mala práctica intentar/atrapar dentro de un try/catch?
es lo que estoy haciendo una mala práctica y tal vez hay una mejor forma de hacer esto:
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
}
}
Parece un poco raro. ¿Hay algo que podría estar mal con eso?
Puede considerar poner el código en el bloque catch en su propio método. –
@HunterMcMillen buen punto. :) – GeekedOut