Conversation
5cf325f to
5737b97
Compare
core/src/test/java/org/apache/iceberg/util/TestExceptionUtil.java
Outdated
Show resolved
Hide resolved
| tryThrowAs(failure, e2Class); | ||
| tryThrowAs(failure, e3Class); | ||
| tryThrowAs(failure, RuntimeException.class); | ||
| throw new RuntimeException("Unknown throwable", failure); |
There was a problem hiding this comment.
How do we get here? Is this just for safety? From what I can tell we only allow the block to have called exceptions for e1 -> e3, and all that's left should be RuntimeExceptions right?
There was a problem hiding this comment.
Originally, this block caught Throwable, but I changed it to Exception thinking that we should not catch Error and run the catch block. In that case, this line was just for safety.
But I've changed it back to Throwable after looking at this comment. I thought more about it and this block does need to run if Error is thrown instead of Exception. If Error is thrown but not caught here, then the finally block will run without the failure set and would throw any exception from that block instead of suppressing it.
I think if we want to do no work when Error is thrown, then this should specifically check for Error, but I think that it is correct to run everything on Error because that's the superclass of things like AssertionError. If an assert fails, we still want to run everything like normal.
aokolnychyi
left a comment
There was a problem hiding this comment.
LGTM, nothing to add to the existing comments. Thanks, @rdblue.
|
Tests are passing, so I'll merge this. Thanks @yyanyy, @RussellSpitzer, and @aokolnychyi for reviewing! |
This adds a utility method that accepts blocks as lambdas and correctly handles exceptions. Catch and finally blocks are always run and any exceptions thrown in those blocks are added to the main block's exception as suppressed exceptions. If the main block does not throw an exception, but finally does then the finally exception is thrown.
This currently supports up to 3 checked exception classes.