このような大量のif/elseブロックの他に、考えられるすべての例外タイプを調べるより洗練された方法がありますか?異なる例外条件を調べるための大量のif/elseブロックの代わりに?
public ModelAndView resolveException(HttpServletRequest request,
HttpServletResponse response, Object obj, Exception e) {
if (e instanceof BadException)
{
displayMessage("That was bad.");
}
else if (e instanceof ReallyBadException)
{
displayMessage("That was really bad.");
}
else if (e instanceof ReallyReallyBadException)
{
displayMessage("That was really really bad.");
}
// ...
// and so on
// ...
return null;
}
"エレガント"を定義します。 – bluefoot
私はtry {throw e} catch(BadException f){} catch(ReallyBadException e){}が優雅なのを見ることができますか? :) –