作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
一个简单的例子:
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 等语言,其中出现未处理的错误导致执行突然停止。
最佳答案
长话短说
总是用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?
关于vim - Vim 脚本有办法在任何错误时停止吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66361016/
我是一名优秀的程序员,十分优秀!