Author Topic: Ignore error and continue execution  (Read 2546 times)

0 Members and 1 Guest are viewing this topic.

vincent.r

  • Newt
  • Posts: 101
Ignore error and continue execution
« on: January 29, 2020, 04:38:57 AM »
Is it possible to continue to execute the program if error occur in middle of program ?

For example

1.(defun c:gli (... / .....)         ;program starts here
2.(getblockinfo x y z ..)         ;function for selection of block and get its attributes
3.(arrangeit x1 y1 z1 ...)         ;sort attribute by alphabeticaly
4.(addnumbers n1 n2 n3...)      ;change numbers in specific attribute value
5.(rewrite lst1 lst2...)         ;write attribute to blocks
6.(changelayers laname)         ;change layer of all selected blocks
7.(getblockname&inspoint xyz)   ;get all blocks name and its insertion point
8.(getscale xyz)            ;get all blocks scale
9.(arrangedata xyz)         ;proccess something
10.(writedata lst)            ;write data to notepad files from list
11.)                     ;end defun here

@ line 5 or 6, if function fail (Due to any reason) to perform, is it possible to continue to execute program till defun ends ?

Any help will be highly appreciable.

kpblc

  • Bull Frog
  • Posts: 396
Re: Ignore error and continue execution
« Reply #1 on: January 29, 2020, 05:42:24 AM »
Try to use vl-catch-all-apply function
Sorry for my English.

vincent.r

  • Newt
  • Posts: 101
Re: Ignore error and continue execution
« Reply #2 on: January 29, 2020, 07:04:53 AM »
Try to use vl-catch-all-apply function

Thanks kpblc for your reply !

vl-catch-all-apply function requires two arguments 1) Function 2) List

In my program I need to call some functions with multiple datatype and parameters . i.e. more than two parameters and multiple datatype.
Example - (getblockinfo  list1     list2   string  Real_number1 Real_number2                  Ename)
                (getblockinfo taglist attrlist *p&id*     420.0               297.0            <Entity name: 2ad5a842aa0>)

I am not expert programmer. Do not understand how to call the sub functions using vl-catch-all-apply. Do I need to use *error* in my main and sub functions ?

Need your help Masters. Thanks in advance.


kpblc

  • Bull Frog
  • Posts: 396
Re: Ignore error and continue execution
« Reply #3 on: January 29, 2020, 07:24:15 AM »
As an example:
Code - Auto/Visual Lisp: [Select]
  1. (defun getstring-no-error (message use-spaces / res) ;|
  2. (getstring-no-error "Enter string" nil)
  3. (getstring-no-error "Enter string" t)
  4. |;
  5.   (if (not
  6.           (setq res (vl-catch-all-apply (function (lambda ()
  7.                                                     (if message
  8.                                                       (getstring use-spaces (strcat "\n" message " <Cancel> : "))
  9.                                                       ) ;_ end of if
  10.                                                     ) ;_ end of lambda
  11.                                                   ) ;_ end of function
  12.                                         ) ;_ end of vl-catch-all-apply
  13.                 ) ;_ end of setq
  14.           ) ;_ end of vl-catch-all-error-p
  15.         ) ;_ end of not
  16.     res
  17.     ) ;_ end of if
  18.   ) ;_ end of defun
Sorry for my English.

kpblc

  • Bull Frog
  • Posts: 396
Re: Ignore error and continue execution
« Reply #4 on: January 29, 2020, 07:26:02 AM »
About your function:
Code - Auto/Visual Lisp: [Select]
  1.         (setq res (vl-catch-all-apply
  2.                     (function (lambda () (getblockinfo list1 list2 string real_number1 real_number2 ename)))
  3.                     ) ;_ end of vl-catch-all-apply
  4.               ) ;_ end of setq
  5.         ) ;_ end of vl-catch-all-error-p
  6.       ) ;_ end of not
  7.   (progn
  8.    ; Do smth if there is no error
  9.    )
  10.   (princ (strcat "\nError execute getblockinfo : " (vl-catch-all-error-message res)))
  11.   ) ;_ end of if
Sorry for my English.

vincent.r

  • Newt
  • Posts: 101
Re: Ignore error and continue execution
« Reply #5 on: January 29, 2020, 08:17:59 AM »
About your function:
Code - Auto/Visual Lisp: [Select]
  1.         (setq res (vl-catch-all-apply
  2.                     (function (lambda () (getblockinfo list1 list2 string real_number1 real_number2 ename)))
  3.                     ) ;_ end of vl-catch-all-apply
  4.               ) ;_ end of setq
  5.         ) ;_ end of vl-catch-all-error-p
  6.       ) ;_ end of not
  7.   (progn
  8.    ; Do smth if there is no error
  9.    )
  10.   (princ (strcat "\nError execute getblockinfo : " (vl-catch-all-error-message res)))
  11.   ) ;_ end of if

Thanks kpblc!
I am working on it, and trying to understand how it works. Will get back to you soon.

vincent.r

  • Newt
  • Posts: 101
Re: Ignore error and continue execution
« Reply #6 on: January 30, 2020, 05:42:13 AM »
About your function:
Code - Auto/Visual Lisp: [Select]
  1.         (setq res (vl-catch-all-apply
  2.                     (function (lambda () (getblockinfo list1 list2 string real_number1 real_number2 ename)))
  3.                     ) ;_ end of vl-catch-all-apply
  4.               ) ;_ end of setq
  5.         ) ;_ end of vl-catch-all-error-p
  6.       ) ;_ end of not
  7.   (progn
  8.    ; Do smth if there is no error
  9.    )
  10.   (princ (strcat "\nError execute getblockinfo : " (vl-catch-all-error-message res)))
  11.   ) ;_ end of if

Thanks kpblc!
I am working on it, and trying to understand how it works. Will get back to you soon.

Yes kpblc, code is working great and flawlessly !

Thanks Again. You made my day.