Trapping error messages
-
When I
group = entities.add_face (my_face_points), andmy_face_pointsare not coplanar, the application crashes. The API indicates that:if (group) puts "OK" else puts "Failed" endBut that didn't work for not coplanar. Is there any way to trap the error message, and continue running the application?
-
begin ### try to do something group = entities.add_face(my_face_points) result="OK." rescue ### what to do if it fails result="MISERABLE FAILURE!" end UI.messagebox(result)
-
@honoluludesktop said:
group = entities.add_face (my_face_points)
- why are you naming the variable
groupwhen you get a face in return? - avoid space between method name and brackets.
- why are you naming the variable
-
Thanks fellows, I will try to run with those tomorrow. Tom, perhaps I should have written
my_facesin place ofgroup. -
@honoluludesktop said:
Thanks fellows, I will try to run with those tomorrow. Tom, perhaps I should have written
my_facesin place ofgroup.It's much easier to follow the code when the variables aren't ambiguously named.
-
You are right, at the time it seemed OK, sorry:-(
-
TIG, Works great. I guess I now have to be careful not to bypass any errors that destroy the data base, and crash SU or the plugin:-)
I tried the following to aid debugging, but the failed command would not run after the Ruby panel opened.
begin group = @entities.add_group(@my_entities) rescue #comes here when @my_entities is not a "add_group" entity result = Sketchup.send_action "showRubyPanel;" group = @entities.add_group(@my_entities)#this did not run endBut I have lots of other uses for it, Thanks.
-
This is a fuller example using multi-rescues
begin # .. the process rescue SyntaxError, NameError => ex print "String doesn't compile; " + ex # .. tidy up rescue SystemCallError => ex print "System Call Error; " + ex # .. tidy up rescue StandardError => ex print "Error running script: " + ex # .. tidy up ensure # .. this is for a 'tidy up' when there's something 'wrong' # .. BUT it's NOT an 'error' per se # .. e.g. f.close unless f.nil? endIf you are using it for 'testing' code then just keep the Ruby Console open...
-
TIG, Thanks, is there a way to open SU with the Ruby Console open? Or, do you debug by keeping SU open, then cut and paste to the Web Console?
-
Add
Sketchup.send_action "showRubyPanel:"
into the start of your script just afterrequire 'sketchup.rb'
BUT remember to ### it out when you are done!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement