aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar brandjon <brandjon@google.com>2017-12-19 08:31:23 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-19 08:32:45 -0800
commit691bd158149602aeb6bbcc46fd4b22367d0157b4 (patch)
tree3d72ae91bb506dff76a8d3785cea2ba5a4aa8fff /src/main/java
parentc93ef7ba6443d7546294eacfe9d21573a11aad70 (diff)
Add convenience method for wrapping SerializationException
RELNOTES: None PiperOrigin-RevId: 179557378
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/serialization/SerializationException.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/SerializationException.java b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/SerializationException.java
index 1477e3a2d1..8efd958087 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/SerializationException.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/SerializationException.java
@@ -46,5 +46,29 @@ public class SerializationException extends Exception {
NoCodecException(String message, NotSerializableRuntimeException e) {
super(message, e);
}
+
+ // Needed for wrapping.
+ NoCodecException(String message, NoCodecException e) {
+ super(message, e);
+ }
+ }
+
+ /**
+ * Throws a {@link SerializationException} with the given message and that wraps the given cause.
+ *
+ * <p>If the cause is a {@link NoCodecException}, the returned exception will also be a {@code
+ * NoCodecException}.
+ *
+ * <p>The return type is {@link SerializationException} rather than {@code void} so that you can
+ * call this function from within a {@code throw} statement. Doing so keeps the calling code more
+ * readable. It also avoids spurious compiler errors, e.g. for using uninitialized variables after
+ * the {@code throw}.
+ */
+ public static SerializationException propagate(String msg, Throwable cause) {
+ if (cause instanceof NoCodecException) {
+ return new NoCodecException(msg, (NoCodecException) cause);
+ } else {
+ return new SerializationException(msg, cause);
+ }
}
}