Tuesday, November 5, 2013

Re: Can I return a Vim error from a function?

On 05/11/13 23:09, Benjamin Klein wrote:
> Is it possible for a user function to return one of the standard Vim errors rather than simply `echo`ing a message?
>
> --
> b
>

You cannot always fake a real Vim exception exactly. See the following
help entries:

*rethrow*
There is no real rethrow in the Vim script language, but you may throw
"v:exception" instead: >

:function! Bar()
: try
: call Foo()
: catch /.*/
: echo "Rethrow" v:exception
: throw v:exception
: endtry
:endfunction
< *try-echoerr*
Note that this method cannot be used to "rethrow" Vim error or interrupt
exceptions, because it is not possible to fake Vim internal exceptions.
Trying so causes an error exception. You should throw your own exception
denoting the situation. If you want to cause a Vim error exception
containing
the original error exception value, you can use the |:echoerr| command: >

:try
: try
: asdf
: catch /.*/
: echoerr v:exception
: endtry
:catch /.*/
: echo v:exception
:endtry

This code displays

Vim(echoerr):Vim:E492: Not an editor command: asdf ~



Best regards,
Tony.
--
There was a young lady named Fleager
Who was terribly, terribly eager
To be all the rage
On the tragedy stage,
Though her talents were pitifully meagre.
-- Edward Gorey

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: