开发者

How can I check if a server exists in Emacs Lisp

开发者 https://www.devze.com 2023-03-07 07:08 出处:网络
I am writing a function that tests for brokens links in an org-mode buffer: (setq urls \'(\"http://google.com\" \"http://bing.com\" \"http://www.yahoo.com\"\"http://thisdoesntexist.net\"))

I am writing a function that tests for brokens links in an org-mode buffer:


    (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)))

This works except when it encounters a non-existent web server. Then it throws a lisp error and opens up a backtrace buffer.

What I would like is way to first test if the server exists and if so then use url-http-file-exists-p to check for a specific document.

Thanks

  • Edited to add sol开发者_如何学编程ution that works for me. Thanks Dov!
    (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)))
    


Why don't you just catch the error through an exception handling condition-case block?

0

精彩评论

暂无评论...
验证码 换一张
取 消