読者です 読者をやめる 読者になる 読者になる

by shigemk2

当面は技術的なことしか書かない

エラー時の処理を記述する

Emacs Lisp

condition-caseを使う

(condition-case nil
    "Normal case"
  (errr "Error!"))			; => "Normal case"
(condition-case nil
    (delete-file "file-not-found!")
  (file-error "File-error!"))		; => "File-error!"
(condition-case err
    (delete-file "file-not-found")
  (error
   err
   ;; => (file-error "Removing old name" "no such file or directory" "/Users/shige/junk/2012/04/file-not-found")
   (error-message-string err)
   ;; => "Removing old name: no such file or directory, /Users/shige/junk/2012/04/file-not-found"
   ))
(condition-case nil
    (err "Error in condition-case")
  (error "In Error handler"))		; => "In Error handler"
(condition-case err
    (error "Error in condition-case")
  (error err))				; => (error "Error in condition-case")

P172

Emacs Lispテクニックバイブル

Emacs Lispテクニックバイブル