• Login
sketchucation logo sketchucation
  • Login
ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

Rescue issue

Scheduled Pinned Locked Moved Developers' Forum
8 Posts 2 Posters 670 Views 2 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.
  • P Offline
    pH7
    last edited by 31 Jul 2016, 19:54

    On purpose, for testing, I raised a RuntimeError inside one of my callback codes. I never reached the rescue clause. I thought maybe that the call to show_modal is asynchronous, and therefore leaving the begin block before the raise occurred. The times I printed disproved this theory, so I am lost now. Can someone explain why I never reached the resume. BTW, I also did a puts in the ensure block and it didn't reach there either.

    def let_user_edit(&success_proc)
    
    	begin
    		puts "Enter let_user_edit #{Time.now.inspect}"
    		op_name = "Edit #{pretty_name} Commands"
    		am = Sketchup.active_model
    		am.start_operation(op_name, true)
    		dialog = ListEditor.getTheDialog
    		dialog.add_action_callback( "callback" ) { |dlg, msg| self.callback_dispatch(dlg,msg) }
    		dialog.set_on_close { dialog.closing(&success_proc) }
    		dialog.show_modal
    		puts "dialog is up#{Time.now.inspect}"
    	rescue 
    		puts "In rescue"
    		self.cancel(dialog)
    		puts "Reraising"
    		raise
    	else
    		# Do code here ONLY if NO errors occur.
    	ensure
    		# ALWAYS do code here errors or not.
    	end
    end # let_user_edit
    
    
    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 31 Jul 2016, 20:02

      Something like:

      rescue => error
        warn error.inspect
        warn error.backtrace.join("\n")
      

      To see what's up...

      TIG

      1 Reply Last reply Reply Quote 0
      • P Offline
        pH7
        last edited by 31 Jul 2016, 22:22

        @unknownuser said:

        Something like:

        rescue => error
        >   warn error.inspect
        >   warn error.backtrace.join("\n")
        > 
        

        To see what's up...

        I tried it, but as I expected, it still didn't reach the rescue, so nothing was displayed.

        1 Reply Last reply Reply Quote 0
        • P Offline
          pH7
          last edited by 31 Jul 2016, 23:04

          I am new to this forum, and I thought I had already done this reply. If it shows up twice - sorry.

          TIG said:
          @unknownuser said:

          Something like:

          rescue => error
          >   warn error.inspect
          >   warn error.backtrace.join("\n")
          > 
          > 
          

          To see what's up...
          I did try this, but as I expected, since it never reaches the rescue, nothing displayed. I should have explicitly stated in my original post that "dialog" is an instance of a class inherited from WebDialog and I should have mentioned that I am on Windows.

          1 Reply Last reply Reply Quote 0
          • T Offline
            TIG Moderator
            last edited by 1 Aug 2016, 11:16

            The 'rescue' only kicks in if you have an error.
            So you don't have an error ??
            The code exits cleanly after the dialog opens...

            Try putting another begin... rescue inside the callback block itself...

            TIG

            1 Reply Last reply Reply Quote 0
            • P Offline
              pH7
              last edited by 1 Aug 2016, 14:41

              TIG said:
              @unknownuser said:

              The 'rescue' only kicks in if you have an error.
              So you don't have an error ??
              The code exits cleanly after the dialog opens...

              The statement that appears right after the "show_modal":

              puts "dialog is up#{Time.now.inspect}"
              

              has not been executed when the error raise occurs. Suspecting that, as you said, "The code exits cleanly after the dialog opens..." is the reason that I displayed the time in that puts statements at the beginning and end of the main code block. If I wait a full minute before clicking the button that causes the callback where my error raise is placed, then the time between the puts on entry and the puts after the show_modal is around a minute. If execution indeed continued immediately after the dialog is displayed, this time difference should be very short. After the error is raised, I can only get the dialog down by clicking on the "X" button of the window. At that time is when I see the puts after the show_modal displayed.

              I would like to have shown the output from the ruby console, but it doesn't let me copy that text. Is there some way to do that if it proves necessary?

              1 Reply Last reply Reply Quote 0
              • T Offline
                TIG Moderator
                last edited by 1 Aug 2016, 15:00

                Place any code you want to run after the dialog opens inside its {} block thus:

                dialog.show_modal{ puts "dialog is up#{Time.now.inspect}" }
                

                TIG

                1 Reply Last reply Reply Quote 0
                • P Offline
                  pH7
                  last edited by 1 Aug 2016, 16:03

                  It isn't that I wanted that "puts" to run immediately after the dialog is up. I put it after the show_modal to determine whether I reach that statement after the dialog is up or if I reach that statement after the dialog closes. I believe that I determined that I reached there only after the dialog closes. Therefore, an error raised in my callbacks should be caught by my rescue and it is not.

                  I am currently working on a solution, suggested by you, to "Try putting another begin... rescue inside the callback block itself..." that is likely to solve my problem. I just wanted to understand why this didn't work and I haven't reached this understanding yet.

                  Edit - that worked fine. My real problem is simply solved. I still don't understand why the original didn't work, but not worth any more of my time or your time. Thanks.

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

                  Advertisement