Possible bug in pattern processing for try/catch blocks

10 views
Skip to first unread message

Jason Franklin

unread,
Oct 24, 2020, 11:15:35 AM10/24/20
to vim-dev
Greetings:

I have discovered that the pattern matching in try/catch blocks does not
conform to my expectations.

Try this example:

try
echoerr 'foo bar baz'
catch /foo/
echo 'caught'
endtry

The string "caught" is printed, as I would expect.

Now try this:

try
echoerr 'foo bar baz'
catch /^foo/
echo 'caught'
endtry

You will see that the message was NOT caught. It appears that using the
"^" metacharacter here causes the message not to match.

Can anyone else confirm this? Is this a bug?

It definitely surprised me.

--
Jason Franklin

Yegappan Lakshmanan

unread,
Oct 24, 2020, 11:55:35 AM10/24/20
to vim_dev, vim-dev
Hi,

The exception that is thrown is "Vim(echoerr):foo bar baz". So if you want to
match the beginning of the exception string, then you need to
use /^Vim(echoerr):foo/

- Yegappan

Reply all
Reply to author
Forward
0 new messages