Author Topic: Universal Error Function  (Read 15095 times)

0 Members and 1 Guest are viewing this topic.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Universal Error Function
« Reply #30 on: March 03, 2006, 10:26:41 AM »
Unbelievable!
Code: [Select]
(SETQ ERROR-LST- (cons '(alert " ERROR") ERROR-LST-))
(*error* "")

whdjr

  • Guest
Re: Universal Error Function
« Reply #31 on: March 03, 2006, 10:33:05 AM »
In the beginning of function I establish a list of the necessary environment variables,
list variable always miscellaneous:
<snip>
It is a universal *error* function :-)

Unbelievable!

WOW!  That is truely amazing.

Se7en,  there is you a great example of eval.

JohnK

  • Administrator
  • Seagull
  • Posts: 10638
Re: Universal Error Function
« Reply #32 on: March 03, 2006, 10:38:34 AM »
Will, I know how to USE eval, i want to know how it works. *smile* Did you every break apart a radio when you were a kid and try to see where the sound was comming from? ...Thats what im doing.

Elpanov, your code scares me. *lol* That little bit of code was so simple...Im speachless. wow.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
Re: Universal Error Function
« Reply #33 on: March 03, 2006, 11:06:30 AM »
Bobby,
After we run our error handler would it be wise to force an error in the last line of our error handler so as to call the global error handler in case the user has modified the global error handler to his liking?

Nope.  If your routine successfully handles it then there is no more exceptional situation for a global error handler to handle.
Bobby C. Jones

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Universal Error Function
« Reply #34 on: March 03, 2006, 02:24:54 PM »
Elpanov
That's a cool routine! 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

LE

  • Guest
Re: Universal Error Function
« Reply #35 on: March 03, 2006, 06:04:37 PM »
In the beginning of function I establish a list of the necessary environment variables,
list variable always miscellaneous:
It is a universal *error* function :-)

ElpanovEvgeniy;

Welcome to theSwamp... do not worried about your English...keep the good code coming.  :kewl:

Luis Esquivel

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Universal Error Function
« Reply #36 on: March 05, 2006, 06:21:39 PM »
Code: [Select]
(SETQ ERROR-LST- (cons '(alert " ERROR") ERROR-LST-))
(*error* "")
I wish to add about (*ERROR* ""):
Code: [Select]
(SETQ ERROR-LST- (cons '(alert "ERROR ... 1") ERROR-LST-))
....
(SETQ ERROR-LST- (cons '(alert " ERROR ....2") (CDR ERROR-LST-)))

'(alert "ERROR") = Any function
Now you will understand, how I use *ERROR *! :-)

kpblc

  • Bull Frog
  • Posts: 396
Re: Universal Error Function
« Reply #37 on: March 06, 2006, 07:01:31 AM »
One more variant for error catcher:
Code: [Select]
;;; Error initializer
(defun kpblc-error (message)
  (if (member message
         '("console break"        "Function cancelled" "quit / exit abort")
         ) ;_member
    (princ "\nFunction cancelled by user")
    (princ
      (strcat "\ERRNO # "
         (itoa (getvar "ERRNO"))
         ": "
         message
         "\n"
         ) ;_strcat
      ) ;_princ
    ) ;_if
  (princ)
  ) ;_defun

;|=============================================================================
*    Saves system variables restore (sysvars saved at global list *kpblc-sysvar-list*)
*    Call params:
*    None
*    Call sample:
(kpblc-error-restore-sysvar)
=============================================================================|;
(defun kpblc-error-restore-sysvar   ()
  (if *kpblc-sysvar-list*
    (foreach item *kpblc-sysvar-list*
      (if (or (vl-catch-all-error-p
       (vl-catch-all-apply 'setvar (list (car item) (cadr item)))
       ) ;_ end of vl-catch-all-error-p
          (= (cadr item) "")
          (wcmatch (strcase (car item) r) "dim*")
          ) ;_ end of and
   (setvar (car item) ".")
   (setvar (car item) (cadr item))
   ) ;_ end of if
      ) ;_ end of foreach
    ) ;_ end of if
  (setq *kpblc-sysvar-list* nil)
  (gc)
  ) ;_ end of defun

;|=============================================================================
*    Saves current values of sysvars at global list *kpblc-sysvar-list* and definind new values for them.
*    Call params:
*   sysvar-list   - list of sysvars with their new values
*    Call samples:
(kpblc-error-sysvar-list (list '("cmdecho" 0) '("blipmode") '("osmode" 503)))
=======================================================================================|;
(defun kpblc-error-save-sysvar (sysvar-list)
  (foreach item   sysvar-list
    (setq *kpblc-sysvar-list*
      (cons
        (list (car item) (getvar (car item)))
        *kpblc-sysvar-list*
        ) ;_ end of cons
     ) ;_ end of setq   
    (if   (cadr item)
      (if (and (vl-catch-all-error-p
       (vl-catch-all-apply 'setvar (list (car item) (cadr item)))
       ) ;_ end of VL-CATCH-ALL-ERROR-P
          (= (cadr item) "")
          (wcmatch (strcase (car item) t) "dim*")
          ) ;_ end of and
   (setvar (car item) ".")
   (setvar (car item) (cadr item))
   ) ;_ end of if
      ) ;_ end of if
    ) ;_ end of foreach
  ) ;_ end of defun
and example for using:
Code: [Select]
(defun (some-function (param1 param2 / *error*)
(setq *error* kpblc-error)
(kpblc-error-save-sysvar '(("osmode" 0) ("cmdecho" 0)))
;;; Doing somethings
(kpblc-error-restore-sysvar)
)
Sorry for my English.