Skip to content

Commit 1d34189

Browse files
committed
patch 8.2.3448: :endtry after function call that throws not found
Problem: :endtry after function call that throws not found. Solution: Do check for following :endtry if an exception is being thrown. (closes #8889)
1 parent d2b98ab commit 1d34189

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

src/testdir/test_trycatch.vim

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2236,7 +2236,7 @@ func Test_user_command_throw_in_function_call()
22362236
catch /my_error/
22372237
let caught = 'yes'
22382238
catch
2239-
let caught = 'no'
2239+
let caught = v:exception
22402240
endtry
22412241
call assert_equal('yes', caught)
22422242
END
@@ -2247,6 +2247,32 @@ func Test_user_command_throw_in_function_call()
22472247
unlet g:caught
22482248
endfunc
22492249

2250+
" Test for using throw in a called function with following endtry {{{1
2251+
func Test_user_command_function_call_with_endtry()
2252+
let lines =<< trim END
2253+
funct s:throw(msg) abort
2254+
throw a:msg
2255+
endfunc
2256+
func s:main() abort
2257+
try
2258+
try
2259+
throw 'err1'
2260+
catch
2261+
call s:throw('err2') | endtry
2262+
catch
2263+
let s:caught = 'yes'
2264+
endtry
2265+
endfunc
2266+
2267+
call s:main()
2268+
call assert_equal('yes', s:caught)
2269+
END
2270+
call writefile(lines, 'XtestThrow')
2271+
source XtestThrow
2272+
2273+
call delete('XtestThrow')
2274+
endfunc
2275+
22502276

22512277
" Modeline {{{1
22522278
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

src/userfunc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5011,14 +5011,16 @@ ex_call(exarg_T *eap)
50115011
--emsg_skip;
50125012
clear_evalarg(&evalarg, eap);
50135013

5014-
// When inside :try we need to check for following "| catch".
5015-
if (!aborting() && (!failed || eap->cstack->cs_trylevel > 0))
5014+
// When inside :try we need to check for following "| catch" or "| endtry".
5015+
// Not when there was an error, but do check if an exception was thrown.
5016+
if ((!aborting() || did_throw)
5017+
&& (!failed || eap->cstack->cs_trylevel > 0))
50165018
{
50175019
// Check for trailing illegal characters and a following command.
50185020
arg = skipwhite(arg);
50195021
if (!ends_excmd2(eap->arg, arg))
50205022
{
5021-
if (!failed)
5023+
if (!failed && !aborting())
50225024
{
50235025
emsg_severe = TRUE;
50245026
semsg(_(e_trailing_arg), arg);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,8 @@ static char *(features[]) =
757757

758758
static int included_patches[] =
759759
{ /* Add new patch number below this line */
760+
/**/
761+
3448,
760762
/**/
761763
3447,
762764
/**/

0 commit comments

Comments
 (0)