Skip to content

Instantly share code, notes, and snippets.

@joshmarlow
Last active August 29, 2015 14:17
Show Gist options
  • Save joshmarlow/00c9f14322951ce900d8 to your computer and use it in GitHub Desktop.
Save joshmarlow/00c9f14322951ce900d8 to your computer and use it in GitHub Desktop.
defun wrapper to assist newbies in debugging
(defparameter defun-super-debug t)
(defmacro defun-wrapped-error (name vars &rest body)
"
A wrapper around defun that will catch any error and note which function it comes from before
re-raising the error.
"
`(defun ,name ,vars
(handler-case
(progn
,@body)
(error (e)
(progn
(format t "!!!!!!!! In function ~a error ~a !!!!!!!!~%" ,(symbol-name name) e)
(error e))))))
;; Define a function
(defun-wrapped-error fe (x y) (+ x y 1))
;; Pass a valid argument and all is well
(fe 3 5)
;; Now pass an invalid argument and get an error
(fe 3 "5")
;; This will print out the following:
;;
;; !!!!!!!! In function FE error Argument Y is not a NUMBER: "5" !!!!!!!!
;; unhandled SIMPLE-TYPE-ERROR: Argument Y is not a NUMBER: "5"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment