예제

public static void main( String[] args ) {
int value = 0;
try {
value = Integer.parseInt( args[ 0 ] );
} catch ( NumberFormatException e0 ) {
try {
value = Integer.parseInt( args[ 1 ] );
} catch ( NumberFormatException e1 ) {
try {
value = Integer.parseInt( args[ 2 ] );
} catch ( NumberFormatException e2 ) {

}
}
}
}

솔루션
전략 디자인 패턴을 사용하십시오.
  1. 타스크 수행을 위한 인터페이스를 작성하십시오.
  2. 타스크를 수행하는 메소드가 예외를 처리하도록 하십시오.
  3. 중첩된 try/catch 블록이 있는 클래스를 전략 컨테이너로 만드십시오.
  4. 중첩된 try/catch 블록을 for 루프로 변경하십시오.
  5. 루프에 예외가 있는 동안 해당 전략을 적용하십시오.

public static void main( String[] args ) {
int value = 0;
for ( int i = 0; i < args.length; i++ ) {
try {
value = Integer.parseInt( args[ i ] );
break ;
} catch ( NumberFormatException e ) {
// Ignore exception
}
}

}