sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.8b introduces important bugfixes for Fredo's Extensions Update

    Rescue Exception

    Scheduled Pinned Locked Moved Developers' Forum
    15 Posts 4 Posters 2.3k Views 4 Watching
    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.
    • thomthomT Offline
      thomthom
      last edited by

      @dan rathbun said:

      So after doing that, I just re-raise the exception, so any debugger or development toolkit can see it.

      I find that pattern useful myself.

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

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        @thomthom said:

        @dan rathbun said:

        So after doing that, I just re-raise the exception, so any debugger or development toolkit can see it.

        I find that pattern useful myself.

        Yes, when we stop, and think a bit,... we should realize that exceptions may not be coming from OUR code, but from other author's code using observers, that may be triggered by our code.

        If we swallow these exceptions at OUR point in the callstack, it could lead to a very frustrating debugging session.

        I did test a few of the StandardError subclases (using my Error raising scriptlets for testing,) and it seems that SketchUp protectively wraps API calls.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jim
          last edited by

          @dan rathbun said:

          If we swallow these exceptions at OUR point in the callstack, it could lead to a very frustrating debugging session.

          I suspect this is currently happening and is what prompted the original topic. This and weird things like:

          2012-12-01_182255.png

          ❓

          Hi

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            @jim said:

            ... and weird things like:

            Looks like Fredo could be overriding Enumerable.each_with_index() or the inherited method in the IO class (or it's subclass File) ??

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              Is it not FredoPaint? It uses observers to hook into material events.

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

              1 Reply Last reply Reply Quote 0
              • fredo6F Offline
                fredo6
                last edited by

                @dan rathbun said:

                @jim said:

                ... and weird things like:

                Looks like Fredo could be overriding Enumerable.each_with_index() or the inherited method in the IO class (or it's subclass File) ??

                Dan,

                My scripts do not subclass any standard Ruby class.
                I think the errors shown in Lib6Traductor.rb comes from the fact that in my utilities to convert strings to length, I use a technique to deliberately provoke an error within a begin / rescue clause in order to find out which locale convention Sketchup is configured for length parsing (basically by testing if "2.3".to_l is valid versus "2,3".to_l).

                Fredo

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  @unknownuser said:

                  My scripts do not subclass any standard Ruby class.

                  It is OK to subclass standard Ruby classes, within your own modules, but not allowed to change standard classes for only your use.

                  @unknownuser said:

                  I think the errors ... comes from the fact that ... I use a technique to deliberately provoke an error within a begin / rescue clause in order to find out which locale convention Sketchup is configured ...

                  OK ... yes I had also done that in several plugins.. and the most recent was VisTools < v1.3.0, so up untilv1.2.1 I was doing this:

                  OLD WAY:

                  #{ Load localized string hashes from file;
                  @@lang = Sketchup.get_locale()[0,2] unless defined?(@@lang)
                  begin
                    if @@lang == 'en'
                      raise(LoadError,"English")
                    else
                      load(File.join(BASEPATH,"VisTools_"<<@@lang<<".rb"))
                    end
                  rescue LoadError => e
                    if e.message != 'English' && !$VERBOSE.nil?
                      puts()
                      puts('NOTICE; Could not find a "VisTools_'<<@@lang<<'.rb" file to load.')
                      puts('Using English text for VisTools plugin UI.')
                      puts()
                    end
                    @@menutext = Hash[
                      ;plugin_name,      "VisTools",
                      #
                      ;hide_layers,      "Hide Layers",
                      ;isolate_layers,   "Isolate Layers",
                      ;hide_entities,    "Hide Entities",
                      ;isolate_entities, "Isolate Entities",
                      ;freeze_entities,  "Freeze Groups/Components",
                      ;unfreeze_all,     "Unfreeze All",
                      ;show_all,         "Show All",
                      #
                      ;debug_mode, "Debug Mode"
                    ]
                    @@tooltips = Hash[
                      ;hide_layers,      "Hide selected layers",
                      ;isolate_layers,   "Isolate selected layers",
                      ;hide_entities,    "Hide selected entities",
                      ;isolate_entities, "Isolate selected entities",
                      ;freeze_entities,  "Freeze groups and components",
                      ;unfreeze_all,     "Unfreeze all",
                      ;show_all,         "Show all layers and entities"
                    ]
                  end #}
                  
                  

                  THEN ... I read the Ruby Style Guide and realized that for various reasons ... using an exception as a conditional / branching construct is VERY BAD CODING STYLE and confusing to anyone reading or debugging the code!

                  So I revised that code block, so it now looks like this in v1.3.0+:

                  #{ String hashes;
                  @@lang = Sketchup.get_locale()[0,2] unless defined?(@@lang)
                  unless @@lang == 'en'
                    # Load localized string hashes from file;
                    begin
                      load(File.join(BASEPATH,"VisTools_"<<@@lang<<".rb"))
                    rescue LoadError => e
                      unless $VERBOSE.nil?
                        puts()
                        puts('NOTICE; Could not find a "VisTools_'<<@@lang<<'.rb" file to load.')
                        puts('Using English text for VisTools plugin UI.')
                        puts()
                      end
                      @@lang == 'en' # just use English
                    end
                  end # load attempt
                  #
                  if @@lang == 'en'
                    @@menutext = Hash[
                      ;plugin_name,      "VisTools",
                      #
                      ;hide_layers,      "Hide Layers",
                      ;isolate_layers,   "Isolate Layers",
                      ;hide_entities,    "Hide Entities",
                      ;isolate_entities, "Isolate Entities",
                      ;freeze_entities,  "Freeze Groups/Components",
                      ;unfreeze_all,     "Unfreeze All",
                      ;show_all,         "Show All",
                      #
                      ;debug_mode, "Debug Mode"
                    ]
                    @@tooltips = Hash[
                      ;hide_layers,      "Hide selected layers",
                      ;isolate_layers,   "Isolate selected layers",
                      ;hide_entities,    "Hide selected entities",
                      ;isolate_entities, "Isolate selected entities",
                      ;freeze_entities,  "Freeze groups and components",
                      ;unfreeze_all,     "Unfreeze all",
                      ;show_all,         "Show all layers and entities"
                    ]
                  end #}
                  
                  

                  It should work the same, but not misuse (ie, raise any unneeded) exceptions.

                  However, a chinese user has just posted an error where it is not working quite correct yet.
                  English should be used, but the user is getting a LoadError... (see the error post).

                  💭

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • fredo6F Offline
                    fredo6
                    last edited by

                    Dan,

                    Thanks for your comments

                    1. I mean my scripts do not alter in anyway the standard Ruby classes and the Sketchup classes too.

                    2. The dot / comma interpretation in Sketchup based on the locale was beyond my understanding and knowledge, so I used this quick way to check whether dot or comma is the decimal separator. I can imagine there will be an API for that in future SU versions.

                    Fredo

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      @unknownuser said:

                      1. The dot / comma interpretation in Sketchup based on the locale was beyond my understanding and knowledge, so I used this quick way to check whether dot or comma is the decimal separator. I can imagine there will be an API for that in future SU versions.

                      I hope so. I've yet to find another way to "detect" the decimal point within SU's Ruby API.

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

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        OK I understand ...

                        Visual Basic:

                        CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator
                        

                        I'm not here much anymore.

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

                        Advertisement