Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Structured Error Handling in VFP 8 : Page 6

With the introduction of Visual FoxPro 3.0, error handling in VFP changed substantially. Rather than using "on error" statements, "state of the art" error events became available. Now, seven years later, more sophisticated error handling mechanisms take center stage as Visual FoxPro 8.0 introduces structured error handling.


advertisement

A Better Explanation of the "Finally" Statement
I still owe you an explanation of the FINALLY statement. In many scenarios, it may seem as if FINALLY may not really be required, since the flow of the program is likely to continue after the Try/Catch section. "Likely" is the key term here. If a potential error is not handled in a Catch block (either because there isn't a matching Catch block or because another exception is thrown), code after the Try/Catch statements may not be executed at all. Consider this example:

   DEFINE CLASS TestClass AS Custom
      FUNCTION Execute
         TRY
            xxxxxx
         CATCH TO oEx
            MESSAGEBOX("Error!")
            THROW oEx
         FINALLY
            MESSAGEBOX("Cleanup Code")
         ENDTRY
         MESSAGEBOX("More Code")
      ENDFUNC
   ENDDEFINE
In this example, the syntax error in the Try block is caught by the Catch block, just to be re-thrown again. This means that the very last MessageBox() will never be executed. However, the MessageBox() in the Finally block will be executed in every case, even if no exception occurred.

Structured Error Handling is one of the most important language enhancements Visual FoxPro has seen in a while. It is very powerful and helps you tremendously in your attempts to produce bullet-proof code.

If you have any questions about this technology, feel free to email me.



Markus Egger is president of EPS Software Corporation, located in Houston, Texas. He is also the founder of EPS Software Austria, located in Salzburg. He concentrates on consulting in COM-based, object-oriented development and Internet applications. He is an international author and speaker, and is co-publisher of Component Developer Magazine. He is also the author of "Advanced Object-Oriented Programming with Visual FoxPro," from Hentzenwerke Publishing. For the past several years, Markus has received the Microsoft MVP award. Several applications he has worked on (mostly as project manager) have received Microsoft Excellence Award nominations. He is the author of several tools, such as GenRepoX (public domain), the Fox Extension Classes, and Visual WebBuilder. A full bio can be found on the web at: www.eps-software.com/MarkusEgger. You can reach Markus at megger@eps-software.com
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date