We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f00ce9c commit b0bb1a0Copy full SHA for b0bb1a0
Jenkinsfile
@@ -627,3 +627,33 @@ void mvn(String args) {
627
sh "mvn $args"
628
}
629
630
+
631
+// try-finally construct that properly suppresses exceptions thrown in the finally block.
632
+def tryFinally(Closure main, Closure ... finallies) {
633
+ def mainFailure = null
634
+ try {
635
+ main()
636
+ }
637
+ catch (Throwable t) {
638
+ mainFailure = t
639
+ throw t
640
641
+ finally {
642
+ finallies.each {it ->
643
644
+ it()
645
646
647
+ if ( mainFailure ) {
648
+ mainFailure.addSuppressed( t )
649
650
+ else {
651
652
653
654
655
656
+ if ( mainFailure ) { // We may reach here if only the "finally" failed
657
+ throw mainFailure
658
659
+}
0 commit comments