Couple of questions regarding handling exceptions
Tomas Volf <[email protected]>
| Newsgroups | gmane.lisp.guile.user |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I would like to dispatch exceptions based on errno, in particular to
return #f on ENOENT, and re-raise the exception otherwise. My current
(working as far as I can tell) solution is:
--8<---------------cut here---------------start------------->8---
(with-exception-handler
(λ (exc)
(and (not (= ENOENT (car (list-ref (exception-args exc) 3))))
(raise-exception exc)))
(λ ()
(with-input-from-file (path realm query) read))
#:unwind? #t
#:unwind-for-type 'system-error)
--8<---------------cut here---------------end--------------->8---
However, I do not consider it very elegant, especially this part:
--8<---------------cut here---------------start------------->8---
(car (list-ref (exception-args exc) 3))
--8<---------------cut here---------------end--------------->8---
Is there better way to do this?
Second question is how to print exceptions including a stack trace. I
noticed there is display-error, however it takes a frame argument and I
am not sure where to get it. I did not found any exception-frame
procedure. However since the default exception-handle *is* able to
print the stack on exception, I assume it is possible. Any tips?
Thanks,
Tomas
--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.
signature.asc
(application/pgp-signature, 853 B)
-----BEGIN PGP SIGNATURE----- iQJCBAEBCgAsFiEEt4NJs4wUfTYpiGikL7/ufbZ/wakFAmeiswIOHH5Ad29sZnNk ZW4uY3oACgkQL7/ufbZ/walTbhAAq8n0rOjy1AlIH/fVlM4a8sgM6UZu4uVbAV29 N5VT4O6BGZe1wbKJJYkAtgE+mrWIbMioWPJRMD9Zb0NdcYbSeswInMEIjUTlEQWI YrB7xDPokiAF8IS7+wVbL/lDmB35jufymIK4KfT4RD0ma3EBMXcmPs/H1aJuIc/t q+rnrb3VECDqWwNMsLJhZz1L4FJuLAxsUqY4bhDLqf5hmlVyCt/f91Ntow14gdH6 kUd15By/FGQWfnFJP/JLOM2Q0vMiYIySWQdoK6RKv+sLAZG/LW+TMH1OrK5GH29h C6xanpSH8mWsKYKmYC2zioLnhZM+1KVMIYdtsdFd6OtS5Lux6rht2F3pS3Zjgx1g nPgr+jOh2c8bdLd75zJtXS6nsfN/vtquUXpzhgb6aSjllS8hc9THsHRHSR7cHfzV RVpznlZHrkUTMbGc4y52NTsLlsn/sKAd1C9FrQqYqnv0ut7+TDEwpketLFiLngBq PT+ERrG+E2hpx/YbL4DDzZIYV3K1JQSkOhdEbISdlclHV0KPdac3BFc2Cuv2ZD/5 8Ws4k0HYHO6zHiCLE+uWGn7t3ptO1OyM4EK4VvEyKjNnBPDT4ZWmbmfht8M0ZMpJ VQjETLK6FCFEaPq7oqz/rRh9go6twBO+PmzLtrOxml4H7RZ/oCNYL2RITxGJojcc MErLBaQ= =Ntiz -----END PGP SIGNATURE-----