Domanda

Is there a way to collect warnings, but still execute the code to which they pertain?

My first thought is to use handler-case to grab all conditions and just continue from warnings, but SimpleWarning in SBCL seems to have no continue restart.

CL-USER> (handler-case (warn "Nope") (t (c) c))
#<SIMPLE-WARNING "Nope" {1008080D53}>
CL-USER> (compute-restarts (handler-case (warn "Nope") (t (c) c)))
(#<RESTART SWANK::RETRY {10080867F3}> #<RESTART ABORT {1004710323}>
 #<RESTART ABORT {1004710073}>)
CL-USER> 
È stato utile?

Soluzione

You need to lookup what WARN actually does. By default it prints a warning. If you want to have access to the condition object, you need to write a handler. Just returning from the handler already continues then. If you want to get rid of the printed warning, then call MUFFLE-WARNING in the handler. MUFFLE-WARNing uses the restart of the same name.

CL-USER 32 > (let ((conditions ))
               (handler-bind ((t (lambda (c) (push c conditions))))
                 (warn "foo")
                 (warn "bar")
                 (format t "~%baz"))
               conditions)
Warning: foo
Warning: bar
baz
(#<SIMPLE-WARNING 402011C9B3> #<SIMPLE-WARNING 402011C63B>)

Altri suggerimenti

Handler-case unwinds when a condition matches one of its clauses. You should use handler-bind.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top