Last active
August 29, 2015 14:17
-
-
Save joshmarlow/00c9f14322951ce900d8 to your computer and use it in GitHub Desktop.
defun wrapper to assist newbies in debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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