changeset 913:3a2a1b06219b

runners: clean up exception propagation schematics.
author shade
date Thu, 17 Jul 2014 21:24:47 +0400
parents 01fe6ebab29e
children 0304b5947dcc
files jmh-core/src/main/java/org/openjdk/jmh/Main.java jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkException.java jmh-core/src/main/java/org/openjdk/jmh/runner/LoopBenchmarkHandler.java jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java
diffstat 4 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/Main.java	Thu Jul 17 19:39:30 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/Main.java	Thu Jul 17 21:24:47 2014 +0400
@@ -76,7 +76,7 @@
                     runner.list();
                 }
             } catch (RunnerException e) {
-                System.err.println("ERROR: " + e.getMessage());
+                System.err.print("ERROR: ");
                 e.printStackTrace(System.err);
             }
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkException.java	Thu Jul 17 19:39:30 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkException.java	Thu Jul 17 21:24:47 2014 +0400
@@ -24,10 +24,10 @@
  */
 package org.openjdk.jmh.runner;
 
+/**
+ * Internal exception in JMH. Always wraps the real cause.
+ */
 public class BenchmarkException extends RuntimeException {
-    public BenchmarkException(String message) {
-        super(message);
-    }
 
     public BenchmarkException(Throwable ex) {
         super(ex);
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/LoopBenchmarkHandler.java	Thu Jul 17 19:39:30 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/LoopBenchmarkHandler.java	Thu Jul 17 21:24:47 2014 +0400
@@ -146,7 +146,8 @@
                 } catch (InterruptedException ex) {
                     throw new BenchmarkException(ex);
                 } catch (ExecutionException ex) {
-                    Throwable cause = ex.getCause().getCause(); // unwrap
+                    // unwrap: ExecutionException -> Throwable-wrapper -> InvocationTargetException
+                    Throwable cause = ex.getCause().getCause().getCause();
                     throw new BenchmarkException(cause);
                 } catch (TimeoutException e) {
                     // try to kick the thread, if it was already started
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Thu Jul 17 19:39:30 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Thu Jul 17 21:24:47 2014 +0400
@@ -586,8 +586,10 @@
             out.endBenchmark(new RunResult(results.get(params)).getAggregatedResult());
 
         } catch (IOException e) {
-            throw new IllegalStateException(e);
+            results.clear();
+            throw new BenchmarkException(e);
         } catch (BenchmarkException e) {
+            results.clear();
             if (options.shouldFailOnError().orElse(Defaults.FAIL_ON_ERROR)) {
                 out.println("Benchmark had encountered error, and fail on error was requested");
                 throw e;