• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Trapping error messages

Scheduled Pinned Locked Moved Developers' Forum
10 Posts 3 Posters 288 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    honoluludesktop
    last edited by 21 Sept 2010, 22:30

    When I group = entities.add_face (my_face_points), and my_face_points are not coplanar, the application crashes. The API indicates that:

    
    if (group)
      puts "OK"
    else
      puts "Failed"
    end
    

    But that didn't work for not coplanar. Is there any way to trap the error message, and continue running the application?

    1 Reply Last reply Reply Quote 0
    • T Online
      TIG Moderator
      last edited by 22 Sept 2010, 09:13

      
      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)
      
      

      🤓

      TIG

      1 Reply Last reply Reply Quote 0
      • T Offline
        thomthom
        last edited by 22 Sept 2010, 09:20

        @honoluludesktop said:

        group = entities.add_face (my_face_points)

        1. why are you naming the variable group when you get a face in return?
        2. avoid space between method name and brackets.

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • H Offline
          honoluludesktop
          last edited by 22 Sept 2010, 13:51

          Thanks fellows, I will try to run with those tomorrow. Tom, perhaps I should have written my_faces in place of group.

          1 Reply Last reply Reply Quote 0
          • T Offline
            thomthom
            last edited by 22 Sept 2010, 13:58

            @honoluludesktop said:

            Thanks fellows, I will try to run with those tomorrow. Tom, perhaps I should have written my_faces in place of group.

            It's much easier to follow the code when the variables aren't ambiguously named.

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • H Offline
              honoluludesktop
              last edited by 22 Sept 2010, 16:06

              You are right, at the time it seemed OK, sorry:-(

              1 Reply Last reply Reply Quote 0
              • H Offline
                honoluludesktop
                last edited by 22 Sept 2010, 23:25

                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
                end
                

                But I have lots of other uses for it, Thanks.

                1 Reply Last reply Reply Quote 0
                • T Online
                  TIG Moderator
                  last edited by 23 Sept 2010, 09:55

                  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?
                  end
                  

                  If you are using it for 'testing' code then just keep the Ruby Console open...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • H Offline
                    honoluludesktop
                    last edited by 23 Sept 2010, 10:47

                    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?

                    1 Reply Last reply Reply Quote 0
                    • T Online
                      TIG Moderator
                      last edited by 23 Sept 2010, 12:01

                      Add Sketchup.send_action "showRubyPanel:"
                      into the start of your script just after require 'sketchup.rb'
                      BUT remember to ### it out when you are done!

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      1 / 1
                      • First post
                        8/10
                        Last post
                      Buy SketchPlus
                      Buy SUbD
                      Buy WrapR
                      Buy eBook
                      Buy Modelur
                      Buy Vertex Tools
                      Buy SketchCuisine
                      Buy FormFonts

                      Advertisement