I'd rather want control over the result. E.g. you might want to have a nil returned if the result is used to test if your code needs to continue down a specific path. So I'd add an argument to the errortrap function to indicate a default return (instead of nil / T) e.g.
Code:
(defun net-error (value)
(and (numberp value) (>= value 0) (<= value 0) (/= value 0)))
(defun error-trap (toEval default / result error debug)
(defun debug (DotNet)
(if *DEBUG*
(princ (strcat "\nError: "
(cond (DotNet *NET-ERROR-MESSAGE*)
((vl-catch-all-error-p error) (vl-catch-all-error-message error))
("Unknown error"))
". While evaluating the expression: "
(vl-princ-to-string toEval)
"\n")))
default)
(cond ((vl-catch-all-error-p
(setq error (vl-catch-all-apply
(function (lambda (output) (set output (eval toEval))))
(list 'result))))
(debug nil))
((net-error result) (debug t))
((null result) default)
(result)))
Then using it:
Code:
_$ (error-trap '(/ 1 0) T)
Error: divide by zero. While evaluating the expression: (/ 1 0)
T
_$ (error-trap '(test-NAN) T)
Error: Testing DotNet LispFunction error token. While evaluating the expression: (test-nan)
T
_$ (error-trap '(test-NAN) nil)
Error: Testing DotNet LispFunction error token. While evaluating the expression: (test-nan)
nil
_$ (error-trap '(test-NAN) 12345)
Error: Testing DotNet LispFunction error token. While evaluating the expression: (test-nan)
12345