Package enhanced-unwind-protect
Description
Simply (:shadowing-import-from #:enhanced-unwind-protect #:
from your defpackage. Don't unwind-protect
)(:use)
!
enhanced-unwind-protect
provides an enhanced unwind-protect that makes it easy
to detect whether the protected form performed a non-local exit or returned normally.
There is a simple well-known pattern for detecting whether a form performed a non-local exit or returned normally, but calling this macro is more readable, concise, ergonomic and convenient.
Distinguishing non-local exits from normal returns can be useful if you want to detect if some operation has "failed" or "succeeded".
You can't just detect if an error has been signaled, since there might be code upstream that knows how to recover from the error without unwinding the stack enough to trigger the cleanup-forms.
Simply (:shadowing-import-from #:enhanced-unwind-protect #:
from your defpackage. Don't unwind-protect
)(:use)
!
(&optional abortp) protected-form &body cleanup-forms => results
t
, nil
or a symbol.Directly expands to cl:unwind-protect
, with trivial variations depending on the abortp argument:
If abortp was not provided, just expand directly to cl:unwind-protect
.
If abortp is t
, then cleanup-forms will be executed only if protected-form performed a non-local exit.
If abortp is nil
, then cleanup-forms will be executed only if protected-form returned normally.
Else, abortp is a variable name, so cleanup-forms will be executed
with abortp bound to t
if protected-form performed a non-local exit, or to nil
if it returned normally.