SlideShare uma empresa Scribd logo
1 de 24
Error Handling in Visual FoxPro
              9.0

          Mike Feltman
Who Am I
•   President F1 Technologies
•   Visual FoxExpress Developer
•   Visual FoxPro Dinosaur
•   mikefeltman@f1tech.com
•   www.f1tech.com
•   www.f1technologies.blogspot.com
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 Fox.wikis.com
      by Randy Pearson
    – CoDe Focus VFP 8 Issue (CodeMagazine.Com)
Thank you!
•   mikefeltman@f1tech.com
•   www.f1tech.com
•   www.f1technologies.blogspot.com
•   419-255-6366

Mais conteúdo relacionado

Mais procurados

Basic javaprogramming(session1)
Basic javaprogramming(session1)Basic javaprogramming(session1)
Basic javaprogramming(session1)
Barm Bannasan
 

Mais procurados (19)

PHP Framework
PHP FrameworkPHP Framework
PHP Framework
 
Phalcon overview
Phalcon overviewPhalcon overview
Phalcon overview
 
PHP framework difference
PHP framework differencePHP framework difference
PHP framework difference
 
Whats next in clientside templating
Whats next in clientside templatingWhats next in clientside templating
Whats next in clientside templating
 
Jak aspekty uporządkują twój kod.
Jak aspekty uporządkują twój kod.Jak aspekty uporządkują twój kod.
Jak aspekty uporządkują twój kod.
 
FireBug And FirePHP
FireBug And FirePHPFireBug And FirePHP
FireBug And FirePHP
 
Dark side of JS development framework
Dark side of JS development frameworkDark side of JS development framework
Dark side of JS development framework
 
Web development with Python
Web development with PythonWeb development with Python
Web development with Python
 
Lecture 23 p1
Lecture 23 p1Lecture 23 p1
Lecture 23 p1
 
Improving the Pharo VM
Improving the Pharo VMImproving the Pharo VM
Improving the Pharo VM
 
Introduction to Web Technology Stacks
Introduction to Web Technology StacksIntroduction to Web Technology Stacks
Introduction to Web Technology Stacks
 
Phinx CloudConf 2016 Presentation
Phinx CloudConf 2016 PresentationPhinx CloudConf 2016 Presentation
Phinx CloudConf 2016 Presentation
 
Lecture 21
Lecture 21Lecture 21
Lecture 21
 
PART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in PythonPART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in Python
 
Uvod u php - Danilo Purić i Tarik Zaimović
Uvod u php - Danilo Purić i Tarik ZaimovićUvod u php - Danilo Purić i Tarik Zaimović
Uvod u php - Danilo Purić i Tarik Zaimović
 
Enterprise PHP
Enterprise PHPEnterprise PHP
Enterprise PHP
 
Developing better PHP projects
Developing better PHP projectsDeveloping better PHP projects
Developing better PHP projects
 
Becoming fully buzzword compliant
Becoming fully buzzword compliantBecoming fully buzzword compliant
Becoming fully buzzword compliant
 
Basic javaprogramming(session1)
Basic javaprogramming(session1)Basic javaprogramming(session1)
Basic javaprogramming(session1)
 

Destaque (7)

Feltman js4 vfp
Feltman js4 vfpFeltman js4 vfp
Feltman js4 vfp
 
Java script for foxpro developers
Java script for foxpro developersJava script for foxpro developers
Java script for foxpro developers
 
Web 101
Web 101Web 101
Web 101
 
Drop acid
Drop acidDrop acid
Drop acid
 
Data definition language (ddl)
Data definition language (ddl)Data definition language (ddl)
Data definition language (ddl)
 
DML Commands
DML CommandsDML Commands
DML Commands
 
Dml and ddl
Dml and ddlDml and ddl
Dml and ddl
 

Semelhante a Error handling in visual fox pro 9

Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010
Clay Helberg
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
Mike Harris
 
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Priyanka Aash
 
Exception handling
Exception handlingException handling
Exception handling
Ravi Sharda
 

Semelhante a Error handling in visual fox pro 9 (20)

Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010
 
News In The Net40
News In The Net40News In The Net40
News In The Net40
 
Vulnerability, exploit to metasploit
Vulnerability, exploit to metasploitVulnerability, exploit to metasploit
Vulnerability, exploit to metasploit
 
Dependable Systems -Software Dependability (15/16)
Dependable Systems -Software Dependability (15/16)Dependable Systems -Software Dependability (15/16)
Dependable Systems -Software Dependability (15/16)
 
Metasploitation part-1 (murtuja)
Metasploitation part-1 (murtuja)Metasploitation part-1 (murtuja)
Metasploitation part-1 (murtuja)
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
 
Php Debugging from the Trenches
Php Debugging from the TrenchesPhp Debugging from the Trenches
Php Debugging from the Trenches
 
Simplifying debugging for multi-core Linux devices and low-power Linux clusters
Simplifying debugging for multi-core Linux devices and low-power Linux clusters Simplifying debugging for multi-core Linux devices and low-power Linux clusters
Simplifying debugging for multi-core Linux devices and low-power Linux clusters
 
Hacker Halted 2014 - RDP Fuzzing And Why the Microsoft Open Protocol Specific...
Hacker Halted 2014 - RDP Fuzzing And Why the Microsoft Open Protocol Specific...Hacker Halted 2014 - RDP Fuzzing And Why the Microsoft Open Protocol Specific...
Hacker Halted 2014 - RDP Fuzzing And Why the Microsoft Open Protocol Specific...
 
exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2
 
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
 
Exception handling
Exception handlingException handling
Exception handling
 
Fuzzing and You: Automating Whitebox Testing
Fuzzing and You: Automating Whitebox TestingFuzzing and You: Automating Whitebox Testing
Fuzzing and You: Automating Whitebox Testing
 
Guide to Destroying Codebases The Demise of Clever Code
Guide to Destroying Codebases   The Demise of Clever CodeGuide to Destroying Codebases   The Demise of Clever Code
Guide to Destroying Codebases The Demise of Clever Code
 
L27
L27L27
L27
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programming
 
CNIT 127: Ch 8: Windows overflows (Part 2)
CNIT 127: Ch 8: Windows overflows (Part 2)CNIT 127: Ch 8: Windows overflows (Part 2)
CNIT 127: Ch 8: Windows overflows (Part 2)
 
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
 
CNIT 127: 8: Windows overflows (Part 2)
CNIT 127: 8: Windows overflows (Part 2)CNIT 127: 8: Windows overflows (Part 2)
CNIT 127: 8: Windows overflows (Part 2)
 
Refactoring
RefactoringRefactoring
Refactoring
 

Mais de Mike Feltman (10)

Feltman collections
Feltman collectionsFeltman collections
Feltman collections
 
What’s new in x case 8
What’s new in x case 8What’s new in x case 8
What’s new in x case 8
 
VFP & Ajax
VFP & AjaxVFP & Ajax
VFP & Ajax
 
Html for desktop applications
Html for desktop applicationsHtml for desktop applications
Html for desktop applications
 
Html and visual fox pro
Html and visual fox proHtml and visual fox pro
Html and visual fox pro
 
Docking from a z in visual fox pro 9
Docking from a z in visual fox pro 9Docking from a z in visual fox pro 9
Docking from a z in visual fox pro 9
 
Client server
Client serverClient server
Client server
 
Introduction to afp
Introduction to afpIntroduction to afp
Introduction to afp
 
Where do you want to go today 2007
Where do you want to go today   2007Where do you want to go today   2007
Where do you want to go today 2007
 
Where do you want to go today
Where do you want to go todayWhere do you want to go today
Where do you want to go today
 

Error handling in visual fox pro 9

  • 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