我正在编写一个函数来测试组织模式缓冲区中的损坏链接:
(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 检查特定文档的方法。
谢谢
- 编辑以添加适合我的解决方案。谢谢多夫!
<pre>(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))) </pre>
最佳答案
为什么不通过异常处理 condition-case
block 捕获错误?
关于emacs - 如何检查 Emacs Lisp 中是否存在服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6050832/