Rethrow stored process canceled exception as a new one with both stacks

This commit is contained in:
Nikolay Krasko
2015-11-06 15:29:08 +03:00
parent 4aa7314600
commit 58dbb1ad53
3 changed files with 57 additions and 1 deletions
@@ -26,6 +26,7 @@ public class WrappedValues {
return "NULL_VALUE";
}
};
public static volatile boolean throwWrappedProcessCanceledException = false;
private final static class ThrowableWrapper {
private final Throwable throwable;
@@ -74,10 +75,23 @@ public class WrappedValues {
@Nullable
public static <V> V unescapeThrowable(@Nullable Object value) {
if (value instanceof ThrowableWrapper) {
throw ExceptionUtilsKt.rethrow(((ThrowableWrapper) value).getThrowable());
Throwable originThrowable = ((ThrowableWrapper) value).getThrowable();
if (throwWrappedProcessCanceledException &&
originThrowable.getClass().getName().equals("com.intellij.openapi.progress.ProcessCanceledException")) {
throw new WrappedProcessCanceledException(originThrowable);
}
throw ExceptionUtilsKt.rethrow(originThrowable);
}
//noinspection unchecked
return (V) value;
}
public static class WrappedProcessCanceledException extends RuntimeException {
public WrappedProcessCanceledException(Throwable cause) {
super("Rethrow stored exception", cause);
}
}
}