Vim 脚本有办法在出现错误时停止吗?

问题描述

一个简单的例子:

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;博士

总是用 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?

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...