Skip to content

Commit

Permalink
Pass the whole exception to a wrapper exception, because e.getCause()…
Browse files Browse the repository at this point in the history
… can be null. Adapt the 'Algorithm could not be loaded'-exception.
  • Loading branch information
tabergma committed Oct 30, 2014
1 parent 4e50d1e commit 854a2bf
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,19 @@ public long executeAlgorithm(String algorithmFileName,
try {
return executeAlgorithmWithValues(algorithmFileName, parameterValues);
} catch (IllegalArgumentException | SecurityException | IllegalAccessException e) {
throw new AlgorithmLoadingException("Could not load the algorithm.", e.getCause());
throw new AlgorithmLoadingException("Could not load the algorithm.", e);
} catch (IOException e) {
throw new AlgorithmLoadingException("IO Exception", e.getCause());
throw new AlgorithmLoadingException("IO Exception", e);
} catch (ClassNotFoundException e) {
throw new AlgorithmLoadingException("Class not found.", e.getCause());
throw new AlgorithmLoadingException("Class not found.", e);
} catch (InstantiationException e) {
throw new AlgorithmLoadingException("Could not instantiate.", e.getCause());
throw new AlgorithmLoadingException("Could not instantiate.", e);
} catch (InvocationTargetException e) {
throw new AlgorithmLoadingException("Could not invoke.", e.getCause());
throw new AlgorithmLoadingException("Could not invoke.", e);
} catch (NoSuchMethodException e) {
throw new AlgorithmLoadingException("No such method.", e.getCause());
throw new AlgorithmLoadingException("No such method.", e);
} catch (EntityStorageException e) {
throw new AlgorithmLoadingException("Algorithm not found in database.", e.getCause());
throw new AlgorithmLoadingException("Algorithm not found in database.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public DefaultDatabaseConnectionGenerator(String dbUrl, String userName, String
this.dbConnection = DriverManager.getConnection(dbUrl, userName, password);
this.dbConnection.setAutoCommit(false);
} catch (SQLException e) {
throw new AlgorithmConfigurationException("Failed to get Database Connection.", e.getCause());
throw new AlgorithmConfigurationException("Failed to get Database Connection.", e);
}
}

Expand All @@ -79,7 +79,7 @@ public RelationalInput generateRelationalInputFromSql(String queryString)
try {
resultSetIterator = new ResultSetIterator(resultSet);
} catch (SQLException e) {
throw new InputGenerationException("Could not construct sql input.", e.getCause());
throw new InputGenerationException("Could not construct sql input.", e);
}

return resultSetIterator;
Expand All @@ -98,13 +98,13 @@ protected ResultSet executeQuery(String queryString) throws InputGenerationExcep
sqlStatement.setFetchSize(getFetchSize());
statements.add(sqlStatement);
} catch (SQLException e) {
throw new InputGenerationException("Could not create sql statement on connection.", e.getCause());
throw new InputGenerationException("Could not create sql statement on connection.", e);
}
ResultSet resultSet;
try {
resultSet = sqlStatement.executeQuery(queryString);
} catch (SQLException e) {
throw new InputGenerationException("Could not execute sql statement.", e.getCause());
throw new InputGenerationException("Could not execute sql statement.", e);
}

return resultSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected PrintStream openStream(String fileSuffix) throws CouldNotReceiveResult
try {
return new PrintStream(new FileOutputStream(getOutputFilePathPrefix() + fileSuffix), true);
} catch (FileNotFoundException e) {
throw new CouldNotReceiveResultException("Could not open result file for writing.", e.getCause());
throw new CouldNotReceiveResultException("Could not open result file for writing.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ public InputValidationException() {
public InputValidationException(String message) {
super(message);
}

public InputValidationException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public int getValue() throws InputValidationException {
try {
val = this.textbox.getValueOrThrow();
} catch (ParseException e) {
throw new InputValidationException("Only numbers are allowed!");
throw new InputValidationException("Only numbers are allowed!", e);
}
if (val == null) {
throw new InputValidationException("You have to enter a number!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public Algorithm addAlgorithm(Algorithm algorithm)
try {
analyzer = new AlgorithmAnalyzer(algorithm.getFileName());
} catch (Exception e) {
throw new AlgorithmLoadingException("Algorithm could not be loaded!", e.getCause());
throw new AlgorithmLoadingException("The jar of the algorithm could not be loaded! (" + e.toString() + ")", e);
}

algorithm.setFd(analyzer.isFunctionalDependencyAlgorithm());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ public long executeAlgorithm(String algorithmFileName, String executionIdentifie
try {
executor = buildExecutor(executionIdentifier);
} catch (FileNotFoundException e) {
throw new AlgorithmExecutionException("Could not generate result file.", e.getCause());
throw new AlgorithmExecutionException("Could not generate result file.", e);
} catch (UnsupportedEncodingException e) {
throw new AlgorithmExecutionException("Could not build temporary file generator.", e.getCause());
throw new AlgorithmExecutionException("Could not build temporary file generator.", e);
}
long executionTime = executor.executeAlgorithm(algorithmFileName, parameters);
try {
executor.close();
} catch (IOException e) {
throw new AlgorithmExecutionException("Could not close algorithm executor.", e.getCause());
throw new AlgorithmExecutionException("Could not close algorithm executor.", e);
}

return executionTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public List<ConfigurationRequirement> retrieveParameters(String algorithmFileNam
try {
algorithm = jarLoader.loadAlgorithm(algorithmFileName);
} catch (Exception e) {
throw new AlgorithmExecutionException(e.getMessage(), e.getCause());
throw new AlgorithmExecutionException(e.getMessage(), e);
}

List<ConfigurationRequirement> configList = algorithm.getConfigurationRequirements();
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 854a2bf

Please sign in to comment.