]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0529: silent! causes following try/catch to not work v9.1.0529
authorLemonBoy <thatlemon@gmail.com>
Thu, 4 Jul 2024 17:23:16 +0000 (19:23 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 4 Jul 2024 17:23:16 +0000 (19:23 +0200)
Problem:  silent! causes following try/catch to not work
          (Malcolm Rowe)
Solution: consider emsg_silent in handle_did_throw() and do not abort
          evaluation flow for :silent! (LemonBoy)

The silent! flag causes the evaluation not to be aborted in case of
uncaught exceptions, adjust handle_did_throw to take this detail into
account.

Fixes the long-standing todo.txt item:
```
Problem that a previous silent ":throw" causes a following try/catch not
to work. (ZyX, 2013 Sep 28) With examples: (Malcolm Rowe, 2015 Dec 24)
Also see #8487 for an example.
```

fixes: #538
closes: #15128

Signed-off-by: LemonBoy <thatlemon@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/todo.txt
src/ex_docmd.c
src/testdir/test_vimscript.vim
src/version.c

index c37a1d4bd1be47f6099f35f5afed436637a368d5..5b15a46b8c6fd5f80318d69b32fff60c9c997062 100644 (file)
@@ -1,4 +1,4 @@
-*todo.txt*      For Vim version 9.1.  Last change: 2024 Jun 03
+*todo.txt*      For Vim version 9.1.  Last change: 2024 Jul 04
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -512,10 +512,6 @@ Information for a specific terminal (e.g. gnome, tmux, konsole, alacritty) is
 spread out.  Make a section with copy/paste examples of script and pointers to
 more information.
 
-Problem that a previous silent ":throw" causes a following try/catch not to
-work. (ZyX, 2013 Sep 28) With examples: (Malcolm Rowe, 2015 Dec 24)
-Also see #8487 for an example.
-
 Request to use "." for the cursor column in search pattern \%<.c and \%<.v.
 (#8179)
 
index 71bfa93222d90f60d8395b8269dacbf90c1b4db4..59d3db4dd1850af26ed263e6fa41747a922f6504 100644 (file)
@@ -1460,8 +1460,13 @@ handle_did_throw(void)
     current_exception->throw_name = NULL;
 
     discard_current_exception();       // uses IObuff if 'verbose'
-    suppress_errthrow = TRUE;
-    force_abort = TRUE;
+
+    // If "silent!" is active the uncaught exception is not fatal.
+    if (emsg_silent == 0)
+    {
+       suppress_errthrow = TRUE;
+       force_abort = TRUE;
+    }
 
     if (messages != NULL)
     {
index 897677957a5aa328565e677944d15ae4a2df515c..21f894e9a3e15abc7f92d2ad961173e74f15547f 100644 (file)
@@ -7536,6 +7536,31 @@ func Test_deeply_nested_source()
   call system(cmd)
 endfunc
 
+func Test_exception_silent()
+  XpathINIT
+  let lines =<< trim END
+  func Throw()
+    Xpath 'a'
+    throw "Uncaught"
+    " This line is not executed.
+    Xpath 'b'
+  endfunc
+  " The exception is suppressed due to the presence of silent!.
+  silent! call Throw()
+  try
+    call DoesNotExist()
+  catch /E117:/
+    Xpath 'c'
+  endtry
+  Xpath 'd'
+  END
+  let verify =<< trim END
+    call assert_equal('acd', g:Xpath)
+  END
+
+  call RunInNewVim(lines, verify)
+endfunc
+
 "-------------------------------------------------------------------------------
 " Modelines                                                                {{{1
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index 07720befc52198d56e0cf910063526b204c386a6..b7812fa0090443e34488ff36e5b208d13d7f8589 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    529,
 /**/
     528,
 /**/