patch 8.2.2141: a user command with try/catch may not catch an expression error
Problem: A user command with try/catch may not catch an expression error.
Solution: When an expression fails check for following "|". (closes #7469)
diff --git a/src/testdir/test_trycatch.vim b/src/testdir/test_trycatch.vim
index 9f670f7..b5ad14c 100644
--- a/src/testdir/test_trycatch.vim
+++ b/src/testdir/test_trycatch.vim
@@ -2199,5 +2199,30 @@
%bwipe!
endfunc
+" Test for using try/catch in a user command with a failing expression {{{1
+func Test_user_command_try_catch()
+ let lines =<< trim END
+ function s:throw() abort
+ throw 'error'
+ endfunction
+
+ command! Execute
+ \ try
+ \ | let s:x = s:throw()
+ \ | catch
+ \ | let g:caught = 'caught'
+ \ | endtry
+
+ let g:caught = 'no'
+ Execute
+ call assert_equal('caught', g:caught)
+ END
+ call writefile(lines, 'XtestTryCatch')
+ source XtestTryCatch
+
+ call delete('XtestTryCatch')
+ unlet g:caught
+endfunc
+
" Modeline {{{1
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
diff --git a/src/testdir/test_vimscript.vim b/src/testdir/test_vimscript.vim
index 8c93199..e50e4d5 100644
--- a/src/testdir/test_vimscript.vim
+++ b/src/testdir/test_vimscript.vim
@@ -6825,7 +6825,7 @@
\ ])
call assert_report("Shouldn't be able to define function")
catch
- call assert_exception('Vim(function):E126: Missing :endfunction')
+ call assert_exception('Vim(function):E1145: Missing heredoc end marker: .')
endtry
" :change
@@ -6845,7 +6845,7 @@
\ ])
call assert_report("Shouldn't be able to define function")
catch
- call assert_exception('Vim(function):E126: Missing :endfunction')
+ call assert_exception('Vim(function):E1145: Missing heredoc end marker: .')
endtry
" :insert
@@ -6865,7 +6865,7 @@
\ ])
call assert_report("Shouldn't be able to define function")
catch
- call assert_exception('Vim(function):E126: Missing :endfunction')
+ call assert_exception('Vim(function):E1145: Missing heredoc end marker: .')
endtry
endfunc