Skip to content

Commit 8f81b22

Browse files
committed
patch 8.2.2351: Vim9: error msg for "throw" in function called with "silent!"
Problem: Vim9: error message for "throw" in function that was called with "silent!". Solution: Do not throw the exception when not caught or displayed. (closes #7672)
1 parent 033135e commit 8f81b22

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/testdir/test_vim9_script.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,19 @@ def Test_throw_skipped()
564564
endif
565565
enddef
566566

567+
def Test_nocatch_throw_silenced()
568+
var lines =<< trim END
569+
vim9script
570+
def Func()
571+
throw 'error'
572+
enddef
573+
silent! Func()
574+
END
575+
writefile(lines, 'XthrowSilenced')
576+
source XthrowSilenced
577+
delete('XthrowSilenced')
578+
enddef
579+
567580
def DeletedFunc(): list<any>
568581
return ['delete me']
569582
enddef

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2351,
753755
/**/
754756
2350,
755757
/**/

src/vim9execute.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,6 +2605,17 @@ call_def_function(
26052605
break;
26062606

26072607
case ISN_THROW:
2608+
if (ectx.ec_trystack.ga_len == 0 && trylevel == 0
2609+
&& emsg_silent)
2610+
{
2611+
// throwing an exception while using "silent!" causes the
2612+
// function to abort but not display an error.
2613+
tv = STACK_TV_BOT(-1);
2614+
clear_tv(tv);
2615+
tv->v_type = VAR_NUMBER;
2616+
tv->vval.v_number = 0;
2617+
goto done;
2618+
}
26082619
--ectx.ec_stack.ga_len;
26092620
tv = STACK_TV_BOT(0);
26102621
if (tv->vval.v_string == NULL

0 commit comments

Comments
 (0)