Vim 脚本是否有办法在出现任何错误时停止?
Do Vim scripts have a way to halt on any error?
一个简单的例子:
function! Foo()
echom 'Starting Foo'
let x = Bar(123) " Function does not exist so E117 occurs.
echom 'Nonetheless, this executes.'
endfunction
Vim 是否有一种机制可以在出现任何错误时中止函数或脚本
发生——换句话说,在精神上类似于 bash
?
中的设置
set -o errexit
澄清一下,我了解如何在 try-catch
中包装容易出错的代码。我是
寻找一种通用机制让 Vim 脚本表现相似
到 Python、Ruby、Perl 等语言,其中出现未处理的错误
导致执行突然停止。
TL;DR
始终使用 abort
标记函数
您的问题最近在 vi.SE 上重复:https://vi.stackexchange.com/questions/29038/how-do-i-make-a-function-stop-when-an-error-occurs/29039#29039
或者,关于同一主题:https://vi.stackexchange.com/questions/15905/when-should-a-function-not-be-defined-with-abort
关于SO,还有一些关于abort
的解释:Vimscript: what's the point of 'abort' in a function definition?
一个简单的例子:
function! Foo()
echom 'Starting Foo'
let x = Bar(123) " Function does not exist so E117 occurs.
echom 'Nonetheless, this executes.'
endfunction
Vim 是否有一种机制可以在出现任何错误时中止函数或脚本
发生——换句话说,在精神上类似于 bash
?
set -o errexit
澄清一下,我了解如何在 try-catch
中包装容易出错的代码。我是
寻找一种通用机制让 Vim 脚本表现相似
到 Python、Ruby、Perl 等语言,其中出现未处理的错误
导致执行突然停止。
TL;DR
始终使用 abort
您的问题最近在 vi.SE 上重复:https://vi.stackexchange.com/questions/29038/how-do-i-make-a-function-stop-when-an-error-occurs/29039#29039 或者,关于同一主题:https://vi.stackexchange.com/questions/15905/when-should-a-function-not-be-defined-with-abort
关于SO,还有一些关于abort
的解释:Vimscript: what's the point of 'abort' in a function definition?