36
loading...
This website collects cookies to deliver better user experience
Few men of action have been able to make a graceful exit at the appropriate time.
// Horrible abuse of exceptions. Don't ever do this!
try {
int i = 0;
while(true)
range[i++].climb();
} catch (ArrayIndexOutOfBoundsException e) {
}
for (Mountain m : range)
m.climb();
try {
executeCommand();
} catch (IllegalStateException e) {
//Highly suspicious. Anything can happen here
//without your knowledge.
}
try {
executeCommand();
} catch (IllegalStateException e) {
// Following log is redundant information.
// It will pollute your error log.
log.error("Exception at doSomething:", e);
throw new BadRequest("Exception has occurred.", e);
}
try {
executeCommand();
} catch (IllegalStateException e) {
throw new CommandArgumentException("Arguments
to command are not right.", e);
}
/**
* JavaDoc Exception sample documentation
* @throws Exception in case of exceptional scenarios.
*/
public void doSomething() throws AnException, AnotherException {
...
}
String serviceA = "Something has happened in serviceA";
String serviceB = "Something has happened in serviceB";
//somewhere else
log.error(serviceA);
//somewhere else
log.error(serviceB);
String errorStatement = "Something has happened in ";
String serviceA = "serviceA";
String serviceB = "serviceB";
//somewhere else
log.error(errorStatement + serviceA);
//somewhere else
log.error(errorStatement + serviceB);
36