lfe011969 Posted January 13, 2011 Share Posted January 13, 2011 I'm using code from VVA found here to retrieve and set custom drawing properties and I'm trying to figure out how to trap out errors. The typical error I get is: ** ERROR: ActiveX Server returned an error: Parameter not optional ** This happens when I think I've assigned a value to a variable then try to set a custom drawing property to that value but in reality the variable is nil. I know I can use (vl-catch-all-apply) but I'm having a tough time figuring it out the correct way to use it. Can anyone give me a generic example of using (vl-catch-all-apply) or some other way to trap out errors while setting these values? Thanks. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 13, 2011 Share Posted January 13, 2011 Test for a nil variable? (if <variable> (dosomestuff) ) Quote Link to comment Share on other sites More sharing options...
VVA Posted January 14, 2011 Share Posted January 14, 2011 Or test for a string variable (if (eq (type <variable>) 'STR) (dosomestuff) ) Quote Link to comment Share on other sites More sharing options...
irneb Posted January 14, 2011 Share Posted January 14, 2011 It's usually not a great idea to rely on the vl-catch-all-apply, it's better to check your variables as Lee & VVA shows ... bbbuuuutttt ... since no-one's shown you the vlcatch-all-apply thingy ... here goes: Say you're using using VVA's _dwgru-dwgprops-set-custom-prop, but instead of trying to test the key and value 1st you simply want it to continue: (if (vl-catch-all-error-p (vl-catch-all-apply '_dwgru-dwgprops-set-custom-prop (list key vale doc)) ) (princ "The value wasn't saved.") (princ "The setting was saved sucsessfully.") ) Basically it evaluates the 1st argument (therefore you need to quote the defun's name). Then it passes the 2nd argument as arguments to the evaluated function - that's why it needs to be in a list. What happens is it returns whatever the function would normally return, except if there's an error. Then it returns an error object - that's what the vl-catch-all-error-p tests for. Quote Link to comment Share on other sites More sharing options...
lfe011969 Posted January 14, 2011 Author Share Posted January 14, 2011 Test for a nil variable? (if <variable> (dosomestuff) ) Or test for a string variable (if (eq (type <variable>) 'STR) (dosomestuff) ) I'm embarrassed to say I didn't even think to do as either of you say. I saw the error and immediately thought to myself this isn't your typical error so I must need to do something special. It's usually not a great idea to rely on the vl-catch-all-apply, it's better to check your variables as Lee & VVA shows ... bbbuuuutttt ... since no-one's shown you the vlcatch-all-apply thingy ... here goes: Say you're using using VVA's _dwgru-dwgprops-set-custom-prop, but instead of trying to test the key and value 1st you simply want it to continue: (if (vl-catch-all-error-p (vl-catch-all-apply '_dwgru-dwgprops-set-custom-prop (list key vale doc)) ) (princ "The value wasn't saved.") (princ "The setting was saved sucsessfully.") ) Basically it evaluates the 1st argument (therefore you need to quote the defun's name). Then it passes the 2nd argument as arguments to the evaluated function - that's why it needs to be in a list. What happens is it returns whatever the function would normally return, except if there's an error. Then it returns an error object - that's what the vl-catch-all-error-p tests for. Irneb, Thanks for the example and your advice!! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 14, 2011 Share Posted January 14, 2011 Another example of vl-catch-all-apply, may offer some insight. http://www.cadtutor.net/forum/showthread.php?55749-vl-catch-all-apply-%28catching-errors%29&p=377850&viewfull=1#post377850 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.