作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 vimscript 中,function
定义可以采用 abort
争论。引用文档,
When the [abort] argument is added, the function will
abort as soon as an error is detected
abort
其实呢?它是否会破坏所有
try...endtry
块?你什么时候想使用它,什么时候你想避免它?
最佳答案
正如 glts 提到的,所有复杂的细节都记录在 :help except-compat
,答案基本上归结为向后兼容性和 Vimscript 固有的灵活性。
从录制的宏到映射到自定义函数,这是一个自然的过程。考虑到这一点,当函数中的命令导致错误(例如 %s/foo/bar/
不匹配且缺少 e
标志)时,处理应该继续。
另一方面,当您编写“工业级”映射时,您几乎总是使用 try..catch
无论如何(为了避免任何多行错误 Error detected while processing function: ...
,而是向用户显示一个很好的错误消息)。
所以在实践中,大多数发布的插件不使用 abort
,但是 try..catch
,对于快速的、即兴的东西,无论如何你通常不太关心错误处理。
关于Vimscript : what's the point of 'abort' in a function definition?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13425648/
我是一名优秀的程序员,十分优秀!