3

org-mode バッファで壊れたリンクをテストする関数を書いています:


    (setq urls '("http://google.com" "http://bing.com" "http://www.yahoo.com"  "http://thisdoesntexist.net"))
    (while (setq nextlink (car urls))
      (if (url-http-file-exists-p nextlink)
          (message "Link works: %s" nextlink)
        (message "Broken Link found: %s" nextlink))
      (setq urls (cdr urls)))

これは、存在しない Web サーバーに遭遇した場合を除いて機能します。次に、lisp エラーをスローし、バックトレースバッファを開きます。

私が望むのは、最初にサーバーが存在するかどうかをテストし、存在する場合は url-http-file-exists-p を使用して特定のドキュメントを確認する方法です。

ありがとう

  • 私のために働く解決策を追加するために編集されました。ありがとうドヴ!
    (while (setq nextlink (car urls))
      (condition-case nil
        (if (url-http-file-exists-p nextlink)
            (message "Link works: %s" nextlink)
          (message "Broken Link found: %s" nextlink))
        ((error) (message "Server not found: %s" nextlink)))
        (setq urls (cdr urls)))
    
4

1 に答える 1

6

condition-case例外処理ブロックを介してエラーをキャッチしてみませんか?

于 2011-05-18T20:58:18.587 に答える