Example usage for com.google.common.io Closer rethrow

List of usage examples for com.google.common.io Closer rethrow

Introduction

In this page you can find the example usage for com.google.common.io Closer rethrow.

Prototype

public <X1 extends Exception, X2 extends Exception> RuntimeException rethrow(Throwable e,
        Class<X1> declaredType1, Class<X2> declaredType2) throws IOException, X1, X2 

Source Link

Document

Stores the given throwable and rethrows it.

Usage

From source file:org.grouplens.lenskit.eval.traintest.TrainTestEvalTask.java

/**
 * Run the evaluation on the train test data source files
 *
 * @return The summary output table./* w  w  w .ja va  2 s  . c om*/
 * @throws org.grouplens.lenskit.eval.TaskExecutionException
 *          Failure of the evaluation
 */
@Override
@SuppressWarnings("PMD.AvoidCatchingThrowable")
public Table perform() throws TaskExecutionException, InterruptedException {
    try {
        experiments = createExperimentSuite();
        measurements = createMeasurementSuite();
        layout = ExperimentOutputLayout.create(experiments, measurements);
        TableBuilder resultsBuilder = new TableBuilder(layout.getResultsLayout());

        logger.info("Starting evaluation of {} algorithms ({} from LensKit) on {} data sets",
                Iterables.size(experiments.getAllAlgorithms()), experiments.getAlgorithms().size(),
                experiments.getDataSets().size());
        Closer closer = Closer.create();

        try {
            outputs = openExperimentOutputs(layout, measurements, resultsBuilder, closer);
            DAGNode<JobGraph.Node, JobGraph.Edge> jobGraph;
            try {
                jobGraph = makeJobGraph(experiments);
            } catch (RecommenderConfigurationException ex) {
                throw new TaskExecutionException("Recommender configuration error", ex);
            }
            if (taskGraphFile != null) {
                logger.info("writing task graph to {}", taskGraphFile);
                JobGraph.writeGraphDescription(jobGraph, taskGraphFile);
            }
            registerTaskListener(jobGraph);

            // tell all metrics to get started
            runEvaluations(jobGraph);
        } catch (Throwable th) {
            throw closer.rethrow(th, TaskExecutionException.class, InterruptedException.class);
        } finally {
            closer.close();
        }

        logger.info("evaluation {} completed", getName());

        return resultsBuilder.build();
    } catch (IOException e) {
        throw new TaskExecutionException("I/O error", e);
    } finally {
        experiments = null;
        measurements = null;
        outputs = null;
        layout = null;
    }
}