Tuesday, November 5, 2013

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

On Nov 5, 2013, at 5:51 PM, Tony Mechelynck <antoine.mechelynck@gmail.com> wrote:

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

I may need to try something described here, I see -- thanks!

A concern I *do* have is not informing a user that a separate error -- involving the user function -- has occurred, and having the error I am trying to catch then repeated, making it more or less like debug output (useful for me while I'm working on this, but not something I'd want to display to other users). I'll see what I can come up with given this.

--
b

Sent from my iPhone

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