See the top rated post in this thread. Click here

Results 1 to 10 of 17

Thread: Error Handling

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    2007-03
    Posts
    32
    Login to Give a bone
    0

    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
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,804
    Login to Give a bone
    0

    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.
    R.K. McSwain | CAD Panacea |

  3. #3
    Member
    Join Date
    2007-03
    Posts
    32
    Login to Give a bone
    0

    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
    Login to Give a bone
    0

    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
    I could stop if I wanted to
    Join Date
    2007-08
    Posts
    201
    Login to Give a bone
    1

    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
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    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
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  7. #7
    I could stop if I wanted to
    Join Date
    2007-08
    Posts
    201
    Login to Give a bone
    0

    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)
    )

Similar Threads

  1. Error Handling
    By whattaz13 in forum AutoLISP
    Replies: 2
    Last Post: 2008-07-16, 01:03 PM
  2. Error Handling
    By jwf in forum AutoCAD Customization
    Replies: 2
    Last Post: 2004-12-03, 07:42 PM
  3. 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
  •