I have the following code that checks for three different properties. Unfortunately each call can throw up to four exceptions that I all have to catch. Can I some how make the code more readable by reducing the amount of try/catch?
public void retrieveSourceCode() {
try {
fileName = RestServices.getInstance().getClassName(getSourceCodeURI());
} catch (ClientProtocolException e) {
fileName = "not available";
e.printStackTrace();
} catch (IOException e) {
fileName = "not available";
e.printStackTrace();
} catch (RestServicesException e) {
fileName = "not available";
e.printStackTrace();
}
if (!(fileName.endsWith(".jar") || fileName.endsWith(".svn-base"))) {
try {
sourceCode = RestServices.getInstance().sendGetRequestJsonTextToString(getSourceCodeURI());
} catch (ClientProtocolException e) {
sourceCode = "not available";
e.printStackTrace();
} catch (IOException e) {
sourceCode = "not available";
e.printStackTrace();
} catch (RestServicesException e) {
sourceCode = "not available";
e.printStackTrace();
}
if (before == null) {
beforeSourceCode = "no before source code available";
} else {
try {
beforeSourceCode = RestServices.getInstance().sendGetRequestJsonTextToString(getBeforeVersionURI());
} catch (ClientProtocolException e) {
beforeSourceCode = "no before source code available";
e.printStackTrace();
} catch (IOException e) {
beforeSourceCode = "no before source code available";
e.printStackTrace();
} catch (RestServicesException e) {
beforeSourceCode = "no before source code available";
e.printStackTrace();
}
}
if (after == null) {
afterSourceCode = "no after source code available";
} else {
try {
afterSourceCode = RestServices.getInstance().sendGetRequestJsonTextToString(getAfterVersionURI());
} catch (ClientProtocolException e) {
afterSourceCode = "no after source code available";
e.printStackTrace();
} catch (IOException e) {
afterSourceCode = "no after source code available";
e.printStackTrace();
} catch (RestServicesException e) {
afterSourceCode = "no after source code available";
e.printStackTrace();
}
}
}
getChangeSet().addAffectedFile(getFileName());
}