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?
精彩评论