Page 3 of 3 FirstFirst 123
Results 21 to 24 of 24

Thread: Error Handling in LISP/Net

  1. #21
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: Error Handling in LISP/Net

    It is not just T/nil it is (T or any value) / nil.

    It is just the 'and' and 'or' expressions recognize nil as no and anything else as yes.

    The error trap returns T or a value for success and nil for failure.

    Error message can also displayed using this variation of the error trap function

    Code:
    (defun ErrorTrap (symFunction / objError result)
     (if (vl-catch-all-error-p
          (setq objError (vl-catch-all-apply
                         '(lambda (XYZ)(set XYZ (eval symFunction)))
                          (list 'result))))
      (and
       DEBUG
       (princ 
        (strcat "\nError: " 
                (vl-catch-all-error-message objError)
                ". While evaluating the expression: "
                (vl-princ-to-string symfunction) "\n"
        )
       )
       nil  
      )
      (or result 
          'T
      )
     )
    )
    Example of code

    Code:
    Command: (setq DEBUG 1)
    Command: (errortrap '(/ 1 0))
    
    Error: divide by zero. While evaluating the expression: (/ 1 0)
    nil
    AutomateCAD

  2. #22
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Error Handling in LISP/Net

    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

  3. #23
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: Error Handling in LISP/Net

    OK, I can see some advantage with adding a default success return variable.

    I have to think about whether I want to adopt it.

    It would be good if that could be an optional argument.

    I still kinda like the simplicity of nil.

    Its all good.

    Did you check out the new ADOX thread?
    AutomateCAD

  4. #24
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Error Handling in LISP/Net

    Quote Originally Posted by peter View Post
    It would be good if that could be an optional argument.
    Yes indeed. Though how to accomplish an optional argument for this in AutoLisp is beyond me. All I can think which might work is to redo that error trap routine in ObjectARX, since you cannot do it through DotNet (some of the arguments would cause errors, since DotNet does not allow stuff like ActiveX objects passed to/fro ALisp).

Page 3 of 3 FirstFirst 123

Similar Threads

  1. Error Handling
    By ticad02 in forum AutoLISP
    Replies: 16
    Last Post: 2009-12-21, 03:39 PM
  2. Error Handling
    By whattaz13 in forum AutoLISP
    Replies: 2
    Last Post: 2008-07-16, 01:03 PM
  3. Error handling
    By dfuehrer in forum AutoLISP
    Replies: 8
    Last Post: 2007-09-24, 04:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •