(require 'stdlib) (let* ((tname (make-temp-name)) (tfile (open-file tname 'write))) (catch 'foo (unwind-protect (progn ;; Use `temporary-file' (printf "writing to %s\n" tname) (write tfile "A test\n") ;; Now force a non-local exit (throw 'foo) (puts "never happens")) ;; This is the CLEANUP-FORM it will _always_ ;; be evaluated, despite the `throw'. (progn (close-file tfile) (printf "removing %s\n" tname) (delete-file tname)))) (puts "done"))