<<< Exception | Index | Java Exception Handling >>> |
The code could use an if statements to handle an exception:
int result = method( parameters ); if ( result == ERROR_CODE_A ) { // handle the problem A } else if ( result == ERROR_CODE_B ) { // handle the problem B } else { // no errors detected }
However, using the if statements may not be the most effective solution:
primarily, because the code that detects the error often cannot handle it;
secondarily, because a large number of error-related ifs will easily
obscure the main flow of the program logic
make the program hard to understand and maintain
introduce new logical problems
The exception mechanism is an object-oriented alternative.
<<< Exception | Index | Java Exception Handling >>> |