Author Topic: question about *error* handers  (Read 3331 times)

0 Members and 1 Guest are viewing this topic.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
question about *error* handers
« on: April 25, 2008, 09:24:10 AM »
what is the purpose of an error handler like this?

Code: [Select]
(defun ERR (msg)
  (princ)
);;ERR
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: question about *error* handers
« Reply #1 on: April 25, 2008, 09:29:34 AM »
It defeats the normal error handler.
Why I don't know.
I usually use something like this:
Make sure you declare the routine *error* so the primary routine is not disengaged.
Code: [Select]
  (defun *error* (msg)
    (if (not
          (member msg  '("console break" "Function cancelled" "quit / exit abort" "")))
       (princ (strcat "\nError: " msg))
    ) ; if
    (and usercmd (setvar "CMDECHO" usercmd))
    (and useros (setvar "osmode" useros))
    (princ)
  ) ; end error function
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.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: question about *error* handers
« Reply #2 on: April 25, 2008, 09:44:35 AM »
i'm trying to fix something wrong in one of the routines i've collected. i keeping getting:

Quote
"Function cancelled" ; error: An error has occurred inside the *error*
functionFunction cancelled

and then it will undo back like 10-20 min. worth of work. it's only happened a couple times in a past year but it's something i want to get ironed out.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: question about *error* handers
« Reply #3 on: April 25, 2008, 10:05:06 AM »
I had one of those command that did that?  Is there a command undo mark in the begining of the code?  I plunk one of these in any lisp that has more than 4 lines of code as a safety. 
Code: [Select]
(vl-cmdf ".undo" "m")
FWIW my lisp coding skills equal to that of a third Grade kid.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: question about *error* handers
« Reply #4 on: April 25, 2008, 10:25:47 AM »
I had one of those command that did that?  Is there a command undo mark in the begining of the code?  I plunk one of these in any lisp that has more than 4 lines of code as a safety. 
Code: [Select]
(vl-cmdf ".undo" "m")
FWIW my lisp coding skills equal to that of a third Grade kid.

not sure about that, but i know that some have the "undo" "begin"

if i add that to the beginning of the routines, do i need to add anything to the end of it? what about command breaks?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: question about *error* handers
« Reply #5 on: April 25, 2008, 10:49:35 AM »
I had one of those command that did that?  Is there a command undo mark in the begining of the code?  I plunk one of these in any lisp that has more than 4 lines of code as a safety. 
Code: [Select]
(vl-cmdf ".undo" "m")
FWIW my lisp coding skills equal to that of a third Grade kid.

not sure about that, but i know that some have the "undo" "begin"

if i add that to the beginning of the routines, do i need to add anything to the end of it? what about command breaks?
Yes you will need undo-end at the end of the lisp.

I chose to do it the dirty way ( I guess  :|) by dropping marks along the way.  When an undo starts to roll back it is forced to stop at nearest mark.  It will only start undoing when there is another call for it by either the user or a lisp.

There is a thread in the depths of the Swamps that explains this better than I.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: question about *error* handers
« Reply #6 on: April 25, 2008, 11:33:06 AM »
I had one of those command that did that?  Is there a command undo mark in the begining of the code?  I plunk one of these in any lisp that has more than 4 lines of code as a safety. 
Code: [Select]
(vl-cmdf ".undo" "m")
FWIW my lisp coding skills equal to that of a third Grade kid.

not sure about that, but i know that some have the "undo" "begin"

if i add that to the beginning of the routines, do i need to add anything to the end of it? what about command breaks?
Yes you will need undo-end at the end of the lisp.

I chose to do it the dirty way ( I guess  :|) by dropping marks along the way.  When an undo starts to roll back it is forced to stop at nearest mark.  It will only start undoing when there is another call for it by either the user or a lisp.

There is a thread in the depths of the Swamps that explains this better than I.

ok, i'll just have to do a little cleanup on some of them. and fix the undo marks. the thing is, it only does it when i get that wierdo error in error message. it has to be that some routine's error handler is all frigged up. i've noticed that sometimes i'll get FUNCTION CANCELED and sometimes i'll get Function Canceled if i escape out of a routine for some reason. some error handler just has to be screwed up.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: question about *error* handers
« Reply #7 on: April 25, 2008, 03:18:29 PM »
I suspect that some routine has an *error* handler but the *error* is not declared like this
Code: [Select]
(defun c:myfunction(/ var1 var2 *error*)
  (defun *error* (msg)

If you see this
Code: [Select]
(defun c:myfunction(/ var1 var2)
  (defun *error* (msg)

Then the regular lisp error handler is displaced and the local one is in charge.
Try loading this:
Code: [Select]
(defun c:test()
  (defun *error* (msg)
    (princ "\My Error handler.")
  )
  (princ)
)
(c:test)

Then at the command prompt enter (/ 2 0)
The division by zero error activates the error handler.
To get rid of the error handler enter (setq *error* nil)
Then try this again (/ 2 0)

So you see the problem is the error handler in charge is doing something to cause another error.
For example if you had a lisp with this error handler
Code: [Select]
  (defun *error* (msg)
    (if (not
          (member msg  '("console break" "Function cancelled" "quit / exit abort" "")))
       (princ (strcat "\nError: " msg))
    ) ; if
    (setvar "CMDECHO" usercmd)
    (setvar "osmode" useros)
    (princ)
  ) ; end error function

The something other than to routine the activated this error handler caused an error the variables usercmd and useros would likely not exist and therefore would cause an error inside the error handler.

Wew, did you get all that?
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.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: question about *error* handers
« Reply #8 on: April 25, 2008, 03:35:02 PM »
I suspect that some routine has an *error* handler but the *error* is not declared like this
Code: [Select]
(defun c:myfunction(/ var1 var2 *error*)
  (defun *error* (msg)

If you see this
Code: [Select]
(defun c:myfunction(/ var1 var2)
  (defun *error* (msg)

Then the regular lisp error handler is displaced and the local one is in charge.
Try loading this:
Code: [Select]
(defun c:test()
  (defun *error* (msg)
    (princ "\My Error handler.")
  )
  (princ)
)
(c:test)

Then at the command prompt enter (/ 2 0)
The division by zero error activates the error handler.
To get rid of the error handler enter (setq *error* nil)
Then try this again (/ 2 0)

So you see the problem is the error handler in charge is doing something to cause another error.
For example if you had a lisp with this error handler
Code: [Select]
  (defun *error* (msg)
    (if (not
          (member msg  '("console break" "Function cancelled" "quit / exit abort" "")))
       (princ (strcat "\nError: " msg))
    ) ; if
    (setvar "CMDECHO" usercmd)
    (setvar "osmode" useros)
    (princ)
  ) ; end error function

The something other than to routine the activated this error handler caused an error the variables usercmd and useros would likely not exist and therefore would cause an error inside the error handler.

Wew, did you get all that?


so basically the routine doesn't nil out the setq's and in this case MOST IMPORTANTLY the *error*.
i'll have to run a check to all routines that have *error* and see if they are nil'd out in the defun c: (/ *error*)

yes or no?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: question about *error* handers
« Reply #9 on: April 25, 2008, 03:38:08 PM »
Yes, every routine with (defun *error* should have (defun c:myroutine (/ *error*)
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.

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: question about *error* handers
« Reply #10 on: April 26, 2008, 12:05:23 AM »
The first one: (defun err ( msg ) (princ) ) suppresses error messages.

You can also toss in an ``escape-escape'' to your error handlers for safe measure. you can use
(command) (command) to do that.

I wrote a nice general error handler you can study/use. you can find that one here.
[ http://www.theswamp.org/index.php?topic=13730.0 ]

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: question about *error* handers
« Reply #11 on: April 26, 2008, 12:19:55 AM »

I agree with Alan regarding this, the error routine should be wrapped local in the relevant routine ... which is AutoDesks accepted and recommended way to do it ...  for the last 10 years or so.

The problem is that there is a LOT of redundant code out there that is continually regurgitated.



kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: question about *error* handers
« Reply #12 on: April 26, 2008, 09:08:01 AM »
TheSwamp.org  (serving the CAD community since 2003)

DHOPP

  • Guest
Re: question about *error* handers
« Reply #13 on: May 02, 2008, 04:41:57 PM »
I suspect that some routine has an *error* handler but the *error* is not declared like this
Code: [Select]
(defun c:myfunction(/ var1 var2 *error*)
  (defun *error* (msg)

If you see this
Code: [Select]
(defun c:myfunction(/ var1 var2)
  (defun *error* (msg)

Then the regular lisp error handler is displaced and the local one is in charge.
Try loading this:
Code: [Select]
(defun c:test()
  (defun *error* (msg)
    (princ "\My Error handler.")
  )
  (princ)
)
(c:test)

Then at the command prompt enter (/ 2 0)
The division by zero error activates the error handler.
To get rid of the error handler enter (setq *error* nil)
Then try this again (/ 2 0)

So you see the problem is the error handler in charge is doing something to cause another error.
For example if you had a lisp with this error handler
Code: [Select]
  (defun *error* (msg)
    (if (not
          (member msg  '("console break" "Function cancelled" "quit / exit abort" "")))
       (princ (strcat "\nError: " msg))
    ) ; if
    (setvar "CMDECHO" usercmd)
    (setvar "osmode" useros)
    (princ)
  ) ; end error function

The something other than to routine the activated this error handler caused an error the variables usercmd and useros would likely not exist and therefore would cause an error inside the error handler.

Wew, did you get all that?


thanks so much for this explanation, as I new lisper I found this very helpful.