Author Topic: Setvar/*error* problem  (Read 1321 times)

0 Members and 1 Guest are viewing this topic.

Daniel J. Ellis

  • Swamp Rat
  • Posts: 811
Setvar/*error* problem
« on: August 21, 2008, 03:06:56 AM »
OK, yippee, I've finally finished the routine I've been working on over the last month or so, but being sensible decided I should add an error handling routine, and put all my setting back after I'd finished.

I therefore put a call to the following at the start of my code:
(DEFUN sstate ()
 (SETQ oldlay (GETVAR "clayer"))
 (SETQ oldfil (GETVAR "filletrad"))
 (SETQ oldtxt (GETVAR "textstyle"))
 (SETQ oldsnap (GETVAR "osmode"))
 (SETQ oldmtxt (GETVAR "mirrtext"))
 (SETQ olderr *error*)
 (SETQ *error* djeerror)
 (PRINC "\nStates stored")   
 (PRINC)
 (c:undos)
)

(DEFUN djeerror (errmsg)
 (IF ;IF
  (NOT errmsg) ;CONDITION
  (SETQ errmsg "UNSPECIFIED ERROR") ;TRUE
 ) ;CLOSE IF
 (PRINC (STRCAT "\nRoutine cancelled: " errmsg)) ;PRINT ERROR MESSAGE TO SCREEN
 (rstate)
)

And a reference to the following at the end of my code:

(DEFUN c:rstate ( / oldlay oldfil oldtxt oldsnap oldmtxt olderr)
 (SETVAR "clayer" oldlay)
 (SETVAR "filletrad" oldfil)
 (SETVAR "textstyle" oldtxt)
 (SETVAR "osmode" oldsnap)
 (SETVAR "mirrtext" oldmtxt)
 (SETQ *error* olderr)
 (c:undoe)
)

undos and undoe refer to simple undo start and stop function.

So I run my routine, and halfway through, press ESC to simulate an error.  Ufortunately I just get the following on the command line:

Routine cancelled: Function cancelled; error: An error has occurred inside the
*error* functionAutoCAD variable setting rejected: "CLAYER" nil

I've tested it on the command land, and all of the getvars ar working, and if I do a manual setvar, that seems to work as well.

Can anybody suggest what I'm doing wrong?


DJE
===
dJE

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Setvar/*error* problem
« Reply #1 on: August 21, 2008, 08:34:31 AM »
Looks like the variable OldLay has not been set or has been reset to nil.

In my error handlers I use this to test for the nil condition:
Code: [Select]
(and oldlay (SETVAR "clayer" oldlay))
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Setvar/*error* problem
« Reply #2 on: August 21, 2008, 08:38:21 AM »
Here is a link to some more info on error handlers
Click Here


Oh, and welcome to TheSwamp :-)
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.

SomeCallMeDave

  • Guest
Re: Setvar/*error* problem
« Reply #3 on: August 21, 2008, 01:04:29 PM »
Welcome to the Swamp.

I think the problem may be that your are declaring your variables GLOBAL in one place (defun sstate) and then using the same names as LOCAL variable in c:rstate. 

I did a bit (very small bit) of testing and it appears that the 'local-ness' in c:rstate will over-ride the 'global-ness' in sstate. 

That may be something that you want to look at.

cjw

  • Guest
Re: Setvar/*error* problem
« Reply #4 on: August 22, 2008, 01:17:57 AM »
Quote
(DEFUN c:rstate ( / oldlay oldfil oldtxt oldsnap oldmtxt olderr)
 (SETVAR "clayer" oldlay)
 (SETVAR "filletrad" oldfil)
 (SETVAR "textstyle" oldtxt)
 (SETVAR "osmode" oldsnap)
 (SETVAR "mirrtext" oldmtxt)
 (SETQ *error* olderr)
 (c:undoe)
)

(DEFUN c:rstate ( / oldlay oldfil oldtxt oldsnap oldmtxt olderr)
->(DEFUN c:rstate ()