On May 17, 12:36 am, Étienne Faure <[email protected]> wrote:
>
> On Mon, May 16, 2011 at 23:51, Spiros Bousbouras <[email protected]> wrote:
> > 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
>
> Like in most programing languages (actually all of which I know), you
> need to 'try' (:he :try) and 'catch' (:he :catch) exceptions.
>
> Your function call could then be:
>
> if 1
>         try
>                 call Foo()
>         catch /.*/
>                 echo "Caught thrown exception (whatever it is)"
>         endtry
> endif
>
> Then the endif can be reached even if an exception is thrown.

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.

-- 
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