Author Topic: vl-catch-all-apply error  (Read 2780 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 493
vl-catch-all-apply error
« on: August 20, 2018, 10:36:27 AM »
Hi,

I'm getting following error in following code :-

CODE:

Code: [Select]
      (vl-catch-all-apply
'setq
(list angg1
      (rtd (angle '(0 0 0) (vlax-curve-getFirstDeriv plobj (vlax-curve-getParamAtPoint plobj prevpnt))))
)
      )

ERROR : error: bad order function: SETQ

But this code works fine without vl-catch-all-apply as follows :-
Code: [Select]
(setq angg1 (rtd (angle '(0 0 0) (vlax-curve-getFirstDeriv plobj (vlax-curve-getParamAtPoint plobj prevpnt)))))

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: vl-catch-all-apply error
« Reply #1 on: August 20, 2018, 10:42:24 AM »
I think the syntax is something like the following two examples.

Code - Auto/Visual Lisp: [Select]
  1. (vl-catch-all-apply
  2.     (lambda ()
  3.       (setq
  4.       ...
  5.  
  6.   (setq pt
  7.         (vl-catch-all-apply
  8.         ...
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

steve.carson

  • Newt
  • Posts: 108
Re: vl-catch-all-apply error
« Reply #2 on: August 20, 2018, 10:59:17 AM »
I'm not all that familiar with the catch-all stuff, but it looks like you would need to quote angg1 ('angg1). What does
 
Code: [Select]
(list angg1
           (rtd (angle '(0 0 0) (vlax-curve-getFirstDeriv plobj (vlax-curve-getParamAtPoint plobj prevpnt))))
)

return?

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: vl-catch-all-apply error
« Reply #3 on: August 20, 2018, 11:02:38 AM »
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: vl-catch-all-apply error
« Reply #4 on: August 20, 2018, 11:25:00 AM »
I really miss talking with Stig.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: vl-catch-all-apply error
« Reply #5 on: August 20, 2018, 12:33:31 PM »
If you really want to apply the catch-all to a variable assignment, you'll need to use the 'set' function to evaluate both arguments, e.g.:

Code - Auto/Visual Lisp: [Select]
  1. _$ (vl-catch-all-apply 'set (list 'sym 5.0))
  2. 5.0
  3. _$ sym
  4. 5.0

However, this is a very odd statement, as variable assignment will rarely fail (unless perhaps you are attempting to assign a value to a protected symbol).

Instead, you would typically enclose the expression or group of expressions which are likely to throw an exception within the catch-all statement, for example, in your case this might appear something like:
Code - Auto/Visual Lisp: [Select]
  1. (setq angg1
  2.     (vl-catch-all-apply
  3.        '(lambda ( )
  4.             (rtd (angle '(0 0 0) (vlax-curve-getFirstDeriv plobj (vlax-curve-getParamAtPoint plobj prevpnt))))
  5.         )
  6.     )
  7. )

This expression catches all exceptions thrown by the vlax-curve-getParamAtPoint, vlax-curve-getFirstDeriv, angle, and rtd functions. You would then test whether the value assigned to the symbol 'angg1' is an error object using vl-catch-all-error-p.

However, in my opinion, I would always advise to avoid this form of programming unless absolutely necessary, as it can hide genuine errors in the logic of the program which should be handled gracefully prior to evaluating a function which would otherwise throw an exception for the given argument.

For this particular case, I would suggest narrowing down the reason for why your program is returning an error whilst evaluating these particular expressions, and the circumstances which give rise to such an error and then including code to gracefully account for it.


JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: vl-catch-all-apply error
« Reply #6 on: August 20, 2018, 03:14:57 PM »
...I would always advise to avoid this form of programming unless absolutely necessary, as it can hide genuine errors in the logic of the program which should be handled gracefully prior to evaluating a function which would otherwise throw an exception for the given argument.

For this particular case, I would suggest narrowing down the reason for why your program is returning an error whilst evaluating these particular expressions, and the circumstances which give rise to such an error and then including code to gracefully account for it.

This is called the "Rule of Repair" and this was why I always seemed to favor the COND structure to the IF structure.
http://www.catb.org/~esr/writings/taoup/html/ch01s06.html#id2878538
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

mailmaverick

  • Bull Frog
  • Posts: 493
Re: vl-catch-all-apply error
« Reply #7 on: August 21, 2018, 02:10:40 AM »
Thanks to all for their valuable inputs.