Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Home
Help
Login
Register
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
Do I really need error checking
« previous
next »
Print
Pages: [
1
] |
Go Down
Author
Topic: Do I really need error checking (Read 1095 times)
0 Members and 1 Guest are viewing this topic.
jlogan02
Bull Frog
Posts: 327
Do I really need error checking
«
on:
December 13, 2022, 06:01:18 PM »
This routine doesn't have any user actions to it except selecting a button that launches the routine. Is there really any reason for error checking for routines that don't have user action required within the code?
Code - Auto/Visual Lisp:
[Select]
(
defun
c:ST01ToBy
(
/
*error*
msg col
)
(
defun
*error*
(
msg
)
(
if
(
not
(
member
msg '
(
"Function cancelled"
"quit / exit abort"
)
)
)
(
princ
(
strcat
"
\n
Error: "
msg
)
)
)
(
princ
)
)
(
setvar
'cmdecho
0
)
(
if
(
setq
col
(
ssget
"X"
'
(
(
0
.
"*Dimension,MultiLeader,Hatch,*Line,*Text,Arc,Circle"
)
(
62
.
1
)
)
)
)
(
foreach
x
(
mapcar
'
cadr
(
ssnamex
col
)
)
(
entmod
(
append
(
entget
x
)
'
(
(
62
.
256
)
)
)
)
)
)
(
command
"_layer"
"Make"
"LINE1"
"color"
"yellow"
"LINE1"
""
)
(
setvar
'cmdecho
1
)
(
princ
)
)
Logged
J. Logan
ACAD 2018
I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10
mhupp
Bull Frog
Posts: 250
Re: Do I really need error checking
«
Reply #1 on:
December 14, 2022, 08:46:14 AM »
Always a potential for an error. you can set variables back to what they were before the lisp was called, or undo changes. the code isn't run unless their is an error so whats the harm?
Code - Auto/Visual Lisp:
[Select]
(
defun
c:ST01ToBy
(
/
*error*
msg col
)
(
defun
*error*
(
msg
)
(
if
(
not
(
member
msg '
(
"Function cancelled"
"quit / exit abort"
)
)
)
(
princ
(
strcat
"
\n
Error: "
msg
)
)
)
(
vla-endundomark
Drawing
)
(
command
"_U"
)
;undo if error
(
setvar
'cmdecho
1
)
;set cmdecho back to one if their is an ERROR
(
princ
)
)
(
setq
Drawing
(
vla-get-activedocument
(
vlax-get-acad-object
)
)
)
(
vla-startundomark
Drawing
)
(
setvar
'cmdecho
0
)
(
if
(
setq
col
(
ssget
"X"
'
(
(
0
.
"*Dimension,MultiLeader,Hatch,*Line,*Text,Arc,Circle"
)
(
62
.
1
)
)
)
)
(
foreach
x
(
mapcar
'
cadr
(
ssnamex
col
)
)
(
entmod
(
append
(
entget
x
)
'
(
(
62
.
256
)
)
)
)
)
)
;(command "_layer" "Make" "LINE1" "color" "yellow" "LINE1" "")
(
entmake
'
(
(
0
.
"LAYER"
)
(
100
.
"AcDbSymbolTableRecord"
)
(
100
.
"AcDbLayerTableRecord"
)
(
2
.
"LINE1"
)
(
70
.
0
)
(
62
.
2
)
)
)
(
setvar
'cmdecho
1
)
(
vla-endundomark
Drawing
)
(
princ
)
)
«
Last Edit: December 15, 2022, 11:10:25 PM by mhupp
»
Logged
jlogan02
Bull Frog
Posts: 327
Re: Do I really need error checking
«
Reply #2 on:
December 14, 2022, 06:43:43 PM »
Good point. It can' t hurt.
Logged
J. Logan
ACAD 2018
I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10
kdub_nz
Mesozoic keyThumper
SuperMod
Water Moccasin
Posts: 2159
class keyThumper<T>:ILazy<T>
Re: Do I really need error checking
«
Reply #3 on:
December 14, 2022, 07:01:35 PM »
Just be careful where you place the 'undo'.
Haven't tested, but I think the 'undo' in your handler will override the setvar ( a couple lines earlier )
Logged
Called Kerry in my other life
Retired; but they dragged me back in !
I live at UTC + 13.00
---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.
jlogan02
Bull Frog
Posts: 327
Re: Do I really need error checking
«
Reply #4 on:
December 15, 2022, 05:20:35 PM »
Thanks. I'll double check.
Logged
J. Logan
ACAD 2018
I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10
mhupp
Bull Frog
Posts: 250
Re: Do I really need error checking
«
Reply #5 on:
December 15, 2022, 11:56:54 PM »
Thanks kdub code updated.
--Edit
Also ran into this the other day. In BricsCAD you can just run the ssget with out an if statement and it wouldn't error if nil. sent a lisp to someone running AutoCAD and it does error if nil. It also had an error trap so nothing was coming up.
They kept typing the command a couple more times. until they asked me why it wasn't working.
so while not displaying the default error maybe display a coustom one like.
Code - Auto/Visual Lisp:
[Select]
(
defun
*error*
(
msg
)
(
if
(
not
(
member
msg '
(
"Function cancelled"
"quit / exit abort"
)
)
)
(
princ
(
strcat
"
\n
Error: "
msg
)
)
(
princ
"
\n
Something Went Wrong Contact: Name Here"
)
)
(
vla-endundomark
Drawing
)
(
command
"_U"
)
;undo if error
(
setvar
'cmdecho
1
)
;set cmdecho back to one if their is an ERROR
(
princ
)
)
«
Last Edit: December 16, 2022, 11:56:56 AM by mhupp
»
Logged
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
Do I really need error checking