Use the Strategy Design Pattern.
- Create an interface for performing the task.
- Make the method that performs the task throw an exception.
- Make the class with the nested try/catch block into a container of strategies.
- Change the nested try/catch block into a for loop
- While there is an exception in the loop, apply the strategies.
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 ) {
}
}
}
|
|