Mercurial > vim
diff src/testdir/test_trycatch.vim @ 23191:3e7723bab4e5 v8.2.2141
patch 8.2.2141: a user command with try/catch may not catch an expression error
Commit: https://github.com/vim/vim/commit/8143a53c533bc7776c57e5db063d185bdd5750f3
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Dec 13 20:26:29 2020 +0100
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 https://github.com/vim/vim/issues/7469)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 13 Dec 2020 20:30:04 +0100 |
parents | 03249b8976a9 |
children | e855eba4ac39 |
line wrap: on
line diff
--- a/src/testdir/test_trycatch.vim +++ b/src/testdir/test_trycatch.vim @@ -2199,5 +2199,30 @@ func Test_BufEnter_exception() %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