Error handling in visual fox pro 9
Upcoming SlideShare
Loading in...5

Error handling in visual fox pro 9



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.



Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Error handling in visual fox pro 9 Error handling in visual fox pro 9 Presentation Transcript

  • Error Handling in Visual FoxPro 9.0 Mike Feltman
  • Who Am I• President F1 Technologies• Visual FoxExpress Developer• Visual FoxPro Dinosaur•••
  • Agenda• Errors Happen• Types of Errors• Error Trapping Methods• Dealing with Errors• Combining Methods
  • Errors Happen • Virtually All Programs Have Errors • All Applications – even “bug free” ones - can encounter an error
  • 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
  • Types of Error Trapping• Native• ON ERROR• Error Method• TRY/CATCH• OTHER
  • Native Error Handling• At Design Time – Cancel, Ignore or Suspend• At Run Time – Cancel or Ignore
  • 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(…)
  • 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
  • ON ERROR• Samples – Error1.prg – cErrorHandler of cError
  • The Error Event• Added in VFP 3.0• Native to all VFP Objects• Error(nError, cMethod, nLine)
  • 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
  • The Error Event• Samples – Error2.prg – cCursor of cData
  • TRY CATCH• Added in VFP 8.0• Structured Error Handling• Format – TRY – CATCH (WHEN) (TO) – THROW – FINALLY – ENDTRY
  • 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
  • The Exception Object & Catch• CATCH always creates a base class exception• Key Properties: ErrorNo Procedure Message UserValue LineContents StackLevel Details
  • 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
  • TRY CATCH• SAMPLES• Error3 – Error9
  • 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.
  • 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
  • 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
  • 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)
  • 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 by Randy Pearson – CoDe Focus VFP 8 Issue (CodeMagazine.Com)
  • Thank you!•••• 419-255-6366