function! Foo()
    throw 0
endfunction

if 1
    call Foo()
endif

When I execute the above script I get
    E605: Exception not caught: 0
[...]
    line    6:
    E171: Missing :endif

But I don't want to catch the exception. This arose in a
situation where I want a command to stop executing if a
certain condition happens and the only way I found to achieve
this is to throw an exception which doesn't get caught. This
worked as planned but I also got the "Missing :endif" message
which made me wonder whether I had forgotten to put an endif
somewhere. My code was simple enough that I was able to
ascertain without much effort that no endif was actually
missing but it made me wonder whether the "Missing :endif"
message is a feature or a bug.

In every programming language I know you can throw exceptions
which don't get caught and you don't get a message that an if
terminator (or any other syntactic terminator) is missing.

Yeah. I doubt it's deliberate, but expect it's a side-effect of the fact
that :if and :endif aren't actually syntactic in Vim. They are just
commands, and Vim keeps track of them as they are executed. If an
exception is thrown, you are jumped to a location where execution does
not pass the :endif and so Vim does not see it and thinks it's missing.

I think most people would realise that when they see an exception
thrown, it's likely that error messages such as missing :endif occurring
after it are bogus. Experienced Vimmers would realise this is because of
the altered execution path and the fact that :endif is merely a command.

Ben.



--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to