Skip to content

Commit

Permalink
core: Avoid wrapping Errors in RuntimeException
Browse files Browse the repository at this point in the history
  • Loading branch information
ejona86 authored and zhangkun83 committed Sep 13, 2016
1 parent c14edca commit 22393f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.base.Throwables;

import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -56,7 +58,8 @@ public void run() {
task.run();
} catch (Throwable t) {
log.log(Level.SEVERE, "Exception while executing runnable " + task, t);
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
Throwables.propagateIfPossible(t);
throw new AssertionError(t);
}
}

Expand Down
18 changes: 9 additions & 9 deletions core/src/main/java/io/grpc/internal/ServerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,10 @@ public void runInContext() {
stream.close(Status.fromThrowable(e), new Metadata());
context.cancel(null);
throw e;
} catch (Throwable t) {
stream.close(Status.fromThrowable(t), new Metadata());
} catch (Error e) {
stream.close(Status.fromThrowable(e), new Metadata());
context.cancel(null);
throw new RuntimeException(t);
throw e;
} finally {
jumpListener.setListener(listener);
}
Expand Down Expand Up @@ -486,9 +486,9 @@ public void runInContext() {
} catch (RuntimeException e) {
internalClose(Status.fromThrowable(e), new Metadata());
throw e;
} catch (Throwable t) {
internalClose(Status.fromThrowable(t), new Metadata());
throw new RuntimeException(t);
} catch (Error e) {
internalClose(Status.fromThrowable(e), new Metadata());
throw e;
}
}
});
Expand All @@ -504,9 +504,9 @@ public void runInContext() {
} catch (RuntimeException e) {
internalClose(Status.fromThrowable(e), new Metadata());
throw e;
} catch (Throwable t) {
internalClose(Status.fromThrowable(t), new Metadata());
throw new RuntimeException(t);
} catch (Error e) {
internalClose(Status.fromThrowable(e), new Metadata());
throw e;
}
}
});
Expand Down

0 comments on commit 22393f9

Please sign in to comment.