エラーハンドリング
作者: 小見 拓
—
最終変更
2012年01月08日 12時11分
エラーハンドリング
- エラー処理のサンプル。全てのエラーに対応。
:try :sleep 10 :catch :echo "catch all error" :endtry "# => エラーが発生すると「catch all error」と表示。
- 「:catch」にキャッチするエラーの種類を書ける
:try :sleep 10 :catch /^Vim:Interrupt$/ :echo "catch CTRL-C" :sleep 3 :endtry "# => Ctrl-Cで中断すると「catch CTRL-C」と表示。
- 「:catch」「:finally」を用いたエラー処理のサンプル。
:try :throw "ERROR2" :catch /ERROR1/ :echo "catch ERROR1" :catch /ERROR2/ :echo "catch ERROR2" :catch /ERROR3/ :echo "catch ERROR3" :catch :echo "catch all error" :finally :echo "in finally" :endtry "# => catch ERROR2 "# => in finally
- 「:throw」でなく「:echoerr」を使用する方法
:try :echoerr "ERROR" :catch :echo "catch ERROR" :endtry "# => catch ERROR
" see also :help catch