diff src/testdir/test_user_func.vim @ 33636:53416c49a7ab v9.0.2059

patch 9.0.2059: outstanding exceptions may be skipped Commit: https://github.com/vim/vim/commit/0ab500dede4edd8d5aee7ddc63444537be527871 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sat Oct 21 11:59:42 2023 +0200 patch 9.0.2059: outstanding exceptions may be skipped Problem: outstanding exceptions may be skipped Solution: When restoring exception state, process remaining outstanding exceptions closes: #13386 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
author Christian Brabandt <cb@256bit.org>
date Sat, 21 Oct 2023 12:15:03 +0200
parents 31fb1a760ad6
children 7de5ae6a0518
line wrap: on
line diff
--- a/src/testdir/test_user_func.vim
+++ b/src/testdir/test_user_func.vim
@@ -904,7 +904,68 @@ func Test_defer_after_exception()
 
   delfunc Defer
   delfunc Foo
+  delfunc Bar
   unlet g:callTrace
 endfunc
 
+" Test for multiple deferred function which throw exceptions.
+" Exceptions thrown by deferred functions should result in error messages but
+" not propagated into the calling functions.
+func Test_multidefer_with_exception()
+  let g:callTrace = []
+  func Except()
+    let g:callTrace += [1]
+    throw 'InnerException'
+    let g:callTrace += [2]
+  endfunc
+
+  func FirstDefer()
+    let g:callTrace += [3]
+    let g:callTrace += [4]
+  endfunc
+
+  func SecondDeferWithExcept()
+    let g:callTrace += [5]
+    call Except()
+    let g:callTrace += [6]
+  endfunc
+
+  func ThirdDefer()
+    let g:callTrace += [7]
+    let g:callTrace += [8]
+  endfunc
+
+  func Foo()
+    let g:callTrace += [9]
+    defer FirstDefer()
+    defer SecondDeferWithExcept()
+    defer ThirdDefer()
+    let g:callTrace += [10]
+  endfunc
+
+  let v:errmsg = ''
+  try
+    let g:callTrace += [11]
+    call Foo()
+    let g:callTrace += [12]
+  catch /TestException/
+    let g:callTrace += [13]
+  catch
+    let g:callTrace += [14]
+  finally
+    let g:callTrace += [15]
+  endtry
+  let g:callTrace += [16]
+
+  call assert_equal('E605: Exception not caught: InnerException', v:errmsg)
+  call assert_equal([11, 9, 10, 7, 8, 5, 1, 3, 4, 12, 15, 16], g:callTrace)
+
+  unlet g:callTrace
+  delfunc Except
+  delfunc FirstDefer
+  delfunc SecondDeferWithExcept
+  delfunc ThirdDefer
+  delfunc Foo
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab