diff options
-rw-r--r-- | src/nvim/eval.c | 6 | ||||
-rw-r--r-- | test/old/testdir/test_trycatch.vim | 25 |
2 files changed, 30 insertions, 1 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index c6a6ef6848..f638b90caa 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2369,7 +2369,11 @@ int eval0(char *arg, typval_T *rettv, exarg_T *eap, evalarg_T *const evalarg) } // Some of the expression may not have been consumed. Do not check for - // a next command to avoid more errors. + // a next command to avoid more errors, unless "|" is following, which + // could only be a command separator. + if (eap != NULL && skipwhite(p)[0] == '|' && skipwhite(p)[1] != '|') { + eap->nextcmd = check_nextcmd(p); + } return FAIL; } diff --git a/test/old/testdir/test_trycatch.vim b/test/old/testdir/test_trycatch.vim index ef20e03126..a87b753a34 100644 --- a/test/old/testdir/test_trycatch.vim +++ b/test/old/testdir/test_trycatch.vim @@ -2220,6 +2220,31 @@ 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 + " Test for using throw in a called function with following error {{{1 func Test_user_command_throw_in_function_call() let lines =<< trim END |