aokolnychyi commented on issue #1904:
URL: https://github.com/apache/iceberg/issues/1904#issuecomment-742524425


   Internally, we have a utility method like this:
   
   ```
     /**
      * Execute a block of code and call the failure callbacks in the catch 
block. If exceptions occur
      * in either the catch or the finally block, they are appended to the list 
of suppressed
      * exceptions in original exception which is then rethrown.
      *
      * This is primarily an issue with `catch { abort() }` or `finally { 
out.close() }` blocks,
      * where the abort/close needs to be called to clean up `out`, but if an 
exception happened
      * in `out.write`, it's likely `out` may be corrupted and `abort` or 
`out.close` will
      * fail as well. This would then suppress the original/likely more 
meaningful
      * exception from the original `out.write` call.
      */
     def tryWithSafeFinallyAndFailureCallbacks[T](block: => T)(catchBlock: => 
Unit = (), finallyBlock: => Unit = ()): T = {
       var originalThrowable: Throwable = null
       try {
         block
       } catch {
         case cause: Throwable =>
           originalThrowable = cause
           try {
             catchBlock
           } catch {
             case t: Throwable =>
               if (originalThrowable != t) {
                 originalThrowable.addSuppressed(t)
               }
           }
           throw originalThrowable
       } finally {
         try {
           finallyBlock
         } catch {
           case t: Throwable if originalThrowable != null && originalThrowable 
!= t =>
             originalThrowable.addSuppressed(t)
             throw originalThrowable
         }
       }
     }
   ```
   
   I think we need a similar variant in Java in Iceberg.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to