Author Topic: Quit without causing error  (Read 5461 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 495
Quit without causing error
« on: April 03, 2015, 09:40:19 AM »
I have a routine in which number of input datas are asked from the user before actual program execution starts.

All inputs are graphically through DCL. There are 5-6 DCL Windows which open one by one and the user has to select required data.

In case the user presses Cancel in any one of the DCL Window, the program execution must stop there itself.

As per DCL, I know how to know that the user has pressed Cancel. But problem is how to stop program execution ?

Till date, I know only of (quit). (quit) is also an error because when we do program debugging and Tick the option of Last Break Source, the program stops at every (quit) call. Thus, it means that (quit) is not a normal way of exiting program and is an error.

What is the normal way of exiting a LISP routine, without an error ?






JohnK

  • Administrator
  • Seagull
  • Posts: 10660
Re: Quit without causing error
« Reply #1 on: April 03, 2015, 09:44:00 AM »
You need an error handler.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

mailmaverick

  • Bull Frog
  • Posts: 495
Re: Quit without causing error
« Reply #2 on: April 03, 2015, 09:49:07 AM »
Dear John

As I mentioned in my original post, if user presses Cancel, then it is not an error.

Program has to stop without an error.

If I use errorhandler routine, then in that also, I have to use (quit).

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Quit without causing error
« Reply #3 on: April 03, 2015, 09:51:40 AM »
..
What is the normal way of exiting a LISP routine, without an error ?
Step through your code and check what throws errors. Then account for that.

Simple Example:
Code - Auto/Visual Lisp: [Select]
  1. ;; Bombs if user presses enter or misses pick
  2. (setq el (entget (car (entsel))))
  3. ;; No error unless ESC
  4. (if (setq e (car (entsel)))
  5.   (setq el (entget e))
  6. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Quit without causing error
« Reply #4 on: April 03, 2015, 09:54:23 AM »
You need to capture the cancel event, save said state to a variable and then have the various levels of your program gracefully exit based on said state (or any other appropriate state). I can't provide a code snip because I'm on my mobile. It's all do-able tho, I and others have done it. tl;dr: In before Lee.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

mailmaverick

  • Bull Frog
  • Posts: 495
Re: Quit without causing error
« Reply #5 on: April 03, 2015, 10:00:14 AM »
..
What is the normal way of exiting a LISP routine, without an error ?
Step through your code and check what throws errors. Then account for that.

Simple Example:
Code - Auto/Visual Lisp: [Select]
  1. ;; Bombs if user presses enter or misses pick
  2. (setq el (entget (car (entsel))))
  3. ;; No error unless ESC
  4. (if (setq e (car (entsel)))
  5.   (setq el (entget e))
  6. )

Dear Ron, as I mentioned earlier, there is no error.

I want to just quit the routine.

JohnK

  • Administrator
  • Seagull
  • Posts: 10660
Re: Quit without causing error
« Reply #6 on: April 03, 2015, 10:06:08 AM »
Dear John

As I mentioned in my original post, if user presses Cancel, then it is not an error.

Program has to stop without an error.

If I use errorhandler routine, then in that also, I have to use (quit).

1. Read MPs post.
2. You need an error handler (many people have them the following is only a start and one version).
http://www.theswamp.org/index.php?topic=13730.msg167503#msg167503
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Quit without causing error
« Reply #7 on: April 03, 2015, 10:12:40 AM »
..
What is the normal way of exiting a LISP routine, without an error ?
Step through your code and check what throws errors. Then account for that.

Simple Example:
Code - Auto/Visual Lisp: [Select]
  1. ;; Bombs if user presses enter or misses pick
  2. (setq el (entget (car (entsel))))
  3. ;; No error unless ESC
  4. (if (setq e (car (entsel)))
  5.   (setq el (entget e))
  6. )

Dear Ron, as I mentioned earlier, there is no error.

I want to just quit the routine.
In my mind (quit) is an error event. That's why you need an error event handler (*error*). You either use an error event handler or you tighten up your code.
« Last Edit: April 03, 2015, 10:27:21 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Quit without causing error
« Reply #8 on: April 03, 2015, 10:20:38 AM »
Pressing escape is not an error, it is an event. You don't need an error handler, you need an event handler. Semantically yours, MP.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Quit without causing error
« Reply #9 on: April 03, 2015, 10:21:41 AM »
In my mind (quit) is an error. That's why you need an error handler. You either use an error handler or you tighten up your code.
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.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Quit without causing error
« Reply #10 on: April 03, 2015, 10:22:13 AM »
Pressing escape is not an error, it is an event. You don't need an error handler, you need an event handler. Semantically yours, MP.
;D  Edit above.
« Last Edit: April 03, 2015, 10:28:04 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Quit without causing error
« Reply #11 on: April 03, 2015, 10:38:07 AM »
C'mon you guys. Do I need to do this from my mobile? Put a button on the dialog. Call it btn_cancel. Caption it "Cancel". Set it's is_cancel property to true. Capture said event. Deal with it.  :-D
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Quit without causing error
« Reply #12 on: April 03, 2015, 10:53:19 AM »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10660
Re: Quit without causing error
« Reply #14 on: April 03, 2015, 04:04:29 PM »
:-D



Coffee does not laugh, especially out loud. Semantically speaking that is.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org