Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Tip: try..except..finally

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Tip: try..except..finally

    Here's a tip. Hope you find it interesting:

    In a lot of langauges, you can add some code that's to be executed no matter what happens in the rest of the routine. For example, if you had coded a freeze:

    ui_freeze(.t.)
    parentform.close()
    vformname.Index_Set(vindexnamevalue)
    vformname.show()
    ui_freeze(.f.)

    And something happened in between the freeze and the unfreeze, your user'd be stuck. So you'd write:

    ui_freeze(.t.)
    try
    parentform.close()
    vformname.Index_Set(vindexnamevalue)
    vformname.show()
    except
    handleError("Houston, we have a problem.")
    finally
    ui_freeze(.f.)
    end try

    The A5 code that I've seen handles it this way:

    ui_freeze(.t.)
    On Error Goto ErrorTrap
    parentform.close()
    vformname.Index_Set(vindexnamevalue)
    vformname.show()
    ui_freeze(.f.)
    end

    ErrorTrap:
    ui_freeze(.f.)
    handleError("Houston, we have a problem.")

    But this is cumbersome, especially if your clean-up code is extensive, not just a line or two.

    However, I discovered you can accomplish the same thing by taking advantage of Xbasic's...em...laxity. :-)

    ui_freeze(.t.)
    On Error Goto ErrorTrap
    parentform.close()
    vformname.Index_Set(vindexnamevalue)
    vformname.show()
    if .f. then 'this code only executes if there's an error
    ErrorTrap:
    handleError("Houston, we have a problem.")
    end if
    ui_freeze(.f.)
    end

    In some Basics, leaping into a block wouldn't be allowed (the interpeter would be confused by the END IF because it hadn't encountered an IF in the first place) but this doesn't seem to bother Xbasic!

    #2
    RE: Tip: try..except..finally

    The more typical way of writing this code would be:

    ui_freeze(.t.)
    On Error Goto ErrorTrap
    parentform.close()
    vformname.Index_Set(vindexnamevalue)
    vformname.show()
    ui_freeze(.f.)
    end

    ErrorTrap:
    handleError("Houston, we have a problem.")
    end

    -Lenny

    Lenny Forziati
    Vice President, Internet Products and Technical Services
    Alpha Software Corporation

    Comment


      #3
      RE: Tip: try..except..finally

      Hi, Lenny. Thanks for the comments.

      I'm confused. You say "The more typical way of writing this code would be:" and then you give code that's almost identical to the code that I gave after saying "The A5 code that I've seen handles it this way".

      Unless I'm missing something, we're in agreement about how it's usually done.

      The point of doing it the way I suggest is to get the equivalent of a "finally" block: That way you don't have to code "ui_freeze(.f.)" and "tbl.close()" and whatever other finalization code you have in two places.

      In your code example, in case of an error, the routine would exit leaving the user-interface frozen, unless I've missed something. The point not being that you meant to show perfect code, but that's the sort of thing that I might do by mistake in real code and not realize till I got the bug report. (And even then not necessarily be able to track down.)

      Comment


        #4
        RE: Tip: try..except..finally

        Hello Blake,

        This is interesting. Two issues come to mind, if you coded the routine the way you 'discovered', if a later version of Alpha Five tightened up the Xbasic, it might break this code.

        On another note, the parentform.close() should be the last command in a script (assuming that the script is being played from a form event, button push, etc on the form) as the script runs in the memory context of the form. In essence this is trying to 'close down' the memory space the script is running in.

        Interesting,

        Jim

        Comment


          #5
          RE: Tip: try..except..finally

          >

          That did occur to me. On the other hand, since it's not trying to =return= from anywhere or continue a loop that hasn't been setup, it should be okay. If/Then/Else blocking is just straight branching, basically.

          Even this solution is only partial; language support for exception handling would be better.

          >

          "Important safety tip. Thanks, Egon!" That would be important for anyone who wrote a script to know; it's not directly relevant to this kind of structure.

          Although, upon experimentation, that doesn't actually seem to be true. For example:

          dim S as C
          S = "Hello, World!"
          parentform.close()
          trace.writeln(S) 'works

          Maybe the context remains in existence until the script closes. That would make sense.

          Comment


            #6
            RE: Tip: try..except..finally

            Yes, my code is essentially what you wrote as your first example. I assumed your handleError() UDF would take care of unfreezing the UI, but now that I look closer at what you wrote, that was a bad assumption.

            The (potential) problem with your second example, besides that it reduces readability a bit, is that it takes advantage of an unexpected behavior that neither you nor I would expect to work. If the Xbasic team "fixes" this in the future, your code will break and you'll have to spend the time to figure out why. It's dangerous to take advantage of a bug - I'm not saying this is or is not a bug because that's not up to me, but I would not be surprised if your second example would not work in a future release.

            -Lenny

            Lenny Forziati
            Vice President, Internet Products and Technical Services
            Alpha Software Corporation

            Comment


              #7
              RE: Tip: try..except..finally

              The (potential) problem with your second example, besides that it reduces readability a bit,

              I would say that, once you were used to the convention, it increases readability. You know that an "If .F." block is exception handling code and that it's followed by finalization code.

              but I would not be surprised if your second example would not work in a future release.

              One of the hazards of working without a language definition. You don't know if what you're doing is supposed to work or not. A compromise, then: We label the finalization block and jump to it if execution has been normal.


              ui_freeze(.t.)
              On Error Goto Exception
              parentform.close()
              vformname.Index_Set(vindexnamevalue)
              vformname.show()
              Goto Finalization

              Exception:
              handleError("Houston, we have a problem.")

              Finalization:
              ui_freeze(.f.)

              Comment


                #8
                RE: Tip: try..except..finally

                My standard approach to this is to put error handling code after the END statement for the script, just as I would embedded functions.

                ui_freeze(.t.)
                On Error Goto Exception
                parentform.close()
                vformname.Index_Set(vindexnamevalue)
                vformname.show()

                Finalization:
                ui_freeze(.f.)
                END

                Exception:
                handleError("Houston, we have a problem.")
                Goto Finalization

                Bill.

                Comment


                  #9
                  RE: Tip: try..except..finally

                  Yeah, that's good, too. Arguably better since the exception code triggers the goto and contains the other goto, and is out-of-the-way so that the normal flow of the routine is apparent.

                  The key is not having to duplicate the finalization code.

                  Comment

                  Working...
                  X