Your SlideShare is downloading. ×
  • Like
Error handling in visual fox pro 9
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Error handling in visual fox pro 9

  • 1,567 views
Published

Session on error handling I gave as a fill in at Southwest Fox I think.

Session on error handling I gave as a fill in at Southwest Fox I think.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
1,567
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
12
Comments
1
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Error Handling in Visual FoxPro 9.0 Mike Feltman
  • 2. Who Am I• President F1 Technologies• Visual FoxExpress Developer• Visual FoxPro Dinosaur• mikefeltman@f1tech.com• www.f1tech.com• www.f1technologies.blogspot.com
  • 3. Agenda• Errors Happen• Types of Errors• Error Trapping Methods• Dealing with Errors• Combining Methods
  • 4. Errors Happen • Virtually All Programs Have Errors • All Applications – even “bug free” ones - can encounter an error
  • 5. Types of Errors• Coding Errors – Syntax Errors, Data Type Mismatch, Invalid # of Parameters, etc.• Environmental Errors – File Corruption, Printer not ready, Resource not Available, File not Found,• User Errors – Duplicate keys, invalid values
  • 6. Types of Error Trapping• Native• ON ERROR• Error Method• TRY/CATCH• OTHER
  • 7. Native Error Handling• At Design Time – Cancel, Ignore or Suspend• At Run Time – Cancel or Ignore
  • 8. ON ERROR• Oldest method in the book• Format: – ON ERROR <action> – ON ERROR * – ON ERROR DO ErrorHandler WITH… – ON ERROR llError = .T. – ON ERROR goErrorHandler.DealWithIt(…)
  • 9. ON ERROR• Pros • Cons – Centralized Mechanism – Removed from offending – Catch all code – Supports RETRY – Forces Monolithic Style – Supports RETURN of error handling – May require additional inline detection of error states in application code – Difficult to deal with specific scenarios
  • 10. ON ERROR• Samples – Error1.prg – cErrorHandler of cError
  • 11. The Error Event• Added in VFP 3.0• Native to all VFP Objects• Error(nError, cMethod, nLine)
  • 12. The Error Event• Pros • Leads to duplicate code – Localized to offending • Can Require Lengthy DO object CASE constructs – Supports RETRY • Turns off ON ERROR error – Supports RETURN handling • May require additional inline detection of error states in application code
  • 13. The Error Event• Samples – Error2.prg – cCursor of cData
  • 14. TRY CATCH• Added in VFP 8.0• Structured Error Handling• Format – TRY – CATCH (WHEN) (TO) – THROW – FINALLY – ENDTRY
  • 15. TRY CATCH• Pros • Cons – Deal w/ errors at the – Adapting Existing Apps source – Can make debugging – Less Cumbersome more difficult – Less Code in specific – No RETRY or RETURN TO routines – Easier recovery in some instances – Nests gracefully
  • 16. The Exception Object & Catch• CATCH always creates a base class exception• Key Properties: ErrorNo Procedure Message UserValue LineContents StackLevel Details
  • 17. The Throw Command• THROW <expression>• Creates an exception• Expression is placed in user value• Can be used any time a TRY CATCH is in Effect• SYS(2410) can be used to detect TRY/CATCH
  • 18. TRY CATCH• SAMPLES• Error3 – Error9
  • 19. OTHER ERROR TRAPPING• TABLEUPDATE() ERRORS – Field Rule Violated 1582 – Record Rule Violated 1583 – Trigger Failed 1539 – Unique Index Violated 1884 – Update Conflict 1585• SQLEXEC(), SQLCOMMIT(), SQLCONNECT(), etc. all populate the AERROR array.
  • 20. Connectivity Errors• Connectivity Error 1526• AERROR() will contain the back-end error(s) – Column 3: ODBC Error Message – Column 4: ODBC State – Column 5: ODBC Error Number – Column 6: Connection Handle• AERROR() can return multiple rows
  • 21. Mixing & Matching• If error is w/in object error event takes precedence• If error is in TRY/CATCH structured error handling takes precedence• If error is in procedural code ON ERROR takes precedence• Samples: Error10 - 16
  • 22. Related Commands & Functions• Error Details • More Info – MESSAGE(), MESSAGE(1) – LIST STATUS – SYS(2018) – LIST MEMORY – AERROR() – LIST OBJECTS• Error Location • Environment – LINENO() – SYS(5) + CURDIR() – PROGRAM(), SYS(16) – SET(“PATH”) – ACALLSTACKINFO() – SET(“CLASSLIB”) – SET(“PROCEDURE”) – SYS(2019) – OS() – Version() – SYS(0)
  • 23. Conclusion• VFP Has a lot of ways to deal with errors• Mixing and Matching the techniques lets you take advantage of all of them• More Info: – VFP Best Practices from Henztenwerke (Rick Schummer) – Structured Error Handling Topic on Fox.wikis.com by Randy Pearson – CoDe Focus VFP 8 Issue (CodeMagazine.Com)
  • 24. Thank you!• mikefeltman@f1tech.com• www.f1tech.com• www.f1technologies.blogspot.com• 419-255-6366