See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Error Handling

  1. #1
    Member
    Join Date
    2007-03
    Posts
    32
    0 Did you find this post helpful? Yes

    Default Error Handling

    I have lisp routines that set a variable for the user osnap settings. Different routines set different osnap settings then at the end of the routine it sets the osmode variable back to the user settings prior to running the command.

    When a user hits escape (or doesn't select anything during the routine and hits enter to end it) the routine does not get to the end to reset osmode to original user settings. I hear something about error handling in a lisp routinein which if a routine doesn't finish it puts the settings back to how the were prior to running the command.

    Can someone guide in how to write this in the lisp files.


    Thank you all.

  2. #2
    Certified AUGI Addict rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Houston
    Posts
    7,996
    0 Did you find this post helpful? Yes

    Default Re: Error Handling

    To get started, open the Developer Help, search for "error handling", then find the topic "Using the *error* Function". If this doesn't get you started towards solving your issue, post back.

  3. #3
    Member
    Join Date
    2007-03
    Posts
    32
    0 Did you find this post helpful? Yes

    Default Re: Error Handling

    I'm still unable to figure this one out. I even found a site that shows how to handle this exact problem, and I can't get the lisp to work right.

    (defun *error* (msg)
    (setvar "osmode" *osnap)
    (princ msg)
    (princ)
    )

    That's the code it tells me to write, but the osnap settings do not restore after an ESC cancel. I have *osnap set to read the users setting prior to the lisp changing osmode, and my lisp resets at the end if the lisp runs through properly. This works fine, but it still doesn't recall the user osmode setting after a cancel

    I'm adding my lisp routine. In the lisp I've posted I use "useros" in place of *osnap.
    Last edited by ticad02; 2009-08-04 at 02:38 PM.

  4. #4
    Member
    Join Date
    2007-03
    Posts
    32
    0 Did you find this post helpful? Yes

    Default Re: Error Handling

    Sorry, the above posted lisp is the original...here's the one with the error handling code I can't get to work.
    Attached Files Attached Files

  5. #5
    100 Club
    Join Date
    2007-08
    Posts
    180
    1 Did you find this post helpful? Yes

    Default Re: Error Handling

    Hi,

    You have to nest and declare local your *error* function

    Code:
    (defun MyFunction (/ *error* osnap)
      (defun *error* (msg)
        (setvar "osmode" *osnap)
        (princ msg)
        (princ)
      )
      (setq osnap (getvar "OSMODE"))
      ;; do your stuff changing osmode here
      (setvar "OSMODE" osnap)
      (princ)
    )

  6. #6
    Administrator RobertB's Avatar
    Join Date
    2001-08
    Location
    Dallas TX USA
    Posts
    5,846
    0 Did you find this post helpful? Yes

    Lightbulb Re: Error Handling

    Quote Originally Posted by 'gile' View Post
    You have to nest and declare local your *error* function

    Code:
    (defun MyFunction (/ *error* osnap)
      (defun *error* (msg)
        (setvar "osmode" *osnap)
        (princ msg)
        (princ)
      )
      (setq osnap (getvar "OSMODE"))
      ;; do your stuff changing osmode here
      (setvar "OSMODE" osnap)
      (princ)
    )
    If you are going to go thru that amount of work, why not make the error routine also handle clean exits and dispense with the needlessly duplicated code? See the post here.
    R. Robert Bell
    Design Technology Manager
    S P A R L I N G
    Opinions expressed are mine alone and do not reflect the views of Sparling.

  7. #7
    100 Club
    Join Date
    2007-08
    Posts
    180
    0 Did you find this post helpful? Yes

    Default Re: Error Handling

    Nice way Robert, you mean something like this ?

    Code:
    (defun c:test (/ *error* osmode)
      (defun *error* (msg)
        (if (and msg
                 (null (member msg '("Function cancelled" "quit / exit abort")))
            )
          (princ (strcat "\nError: " msg))
        )
        (setvar "osmode" osmode)
        (princ)
      )
      (setq osmode (getvar "OSMODE"))
      ;; do your stuff changing osmode here
      (*error* msg)
    )

  8. #8
    Administrator RobertB's Avatar
    Join Date
    2001-08
    Location
    Dallas TX USA
    Posts
    5,846
    0 Did you find this post helpful? Yes

    Default Re: Error Handling

    Quote Originally Posted by 'gile' View Post
    Nice way Robert, you mean something like this ?

    Code:
    (defun c:test (/ *error* osmode)
      (defun *error* (msg)
        (if (and msg
                 (null (member msg '("Function cancelled" "quit / exit abort")))
            )
          (princ (strcat "\nError: " msg))
        )
        (setvar "osmode" osmode)
        (princ)
      )
      (setq osmode (getvar "OSMODE"))
      ;; do your stuff changing osmode here
      (*error* msg)
    )
    Almost. It is just the last statement that needs a revision:

    Code:
      ;; do your stuff changing osmode here
      (*error* nil)
    )
    R. Robert Bell
    Design Technology Manager
    S P A R L I N G
    Opinions expressed are mine alone and do not reflect the views of Sparling.

  9. #9
    Member
    Join Date
    2007-03
    Posts
    32
    0 Did you find this post helpful? Yes

    Default Re: Error Handling

    Either I'm missing something or I just can't figure it out. I've tried all the mentioned ideas and haven't come up with anything that works. I can't even trouble shoot my attempts as I don't know if I'm even writing the right code in the right places. I'm pretty much just shooting in the dark (lisp at its finest LOL).

    I've attached my three attempts maybe someone can make heads or tails out of what my problem is. Note1.lsp jams up ACAD and I have to go to the task manager to close it. By the way I'm using ACAD 2010 if that changes anything.

    I don't want it written for me, I won't learn anything that way, but if I had a little more guidance about where I was going wrong I may be able to get an the right path.

    Thanks again for everyones patienece and advice.
    Attached Files Attached Files

  10. #10
    I could stop if I wanted to
    Join Date
    2003-12
    Location
    Pittsburgh, PA
    Posts
    355
    0 Did you find this post helpful? Yes

    Default Re: Error Handling

    Maybe this will be of interest to you
    http://www.afralisp.net/lispa/lisp6.htm

Page 1 of 2 12 LastLast

Similar Threads

  1. Error Handling
    By whattaz13 in forum AutoLISP
    Replies: 2
    Last Post: 2008-07-16, 01:03 PM
  2. Error handling
    By dfuehrer in forum AutoLISP
    Replies: 8
    Last Post: 2007-09-24, 04:17 PM
  3. Error Handling
    By jwf in forum AutoCAD Customization
    Replies: 2
    Last Post: 2004-12-03, 06:42 PM
  4. Error Handling:
    By spencer.67965 in forum AutoLISP
    Replies: 4
    Last Post: 2004-09-15, 09:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •