Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Returning from a class method on error.
Message
 
 
To
07/12/2001 14:43:13
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00591378
Message ID:
00591439
Views:
25
Unless you are testing for an error condition throughout the GenKey method, there is no elegant way to return back to the Form.Add method. By default, once an error is processed, code execution continues at the next line after the one that caused the error. During your testing, if you find places that could cause an error, then you should follow that line with a test of your error flag. If the flag is true, the return and abort further execution of code in that method. If you do not want to do that, in the Form.Add, their is a most simplistic approach:
lcOnError = on('error')
on error return -1
lnRetVal = Form1.cstGetKey.GenKey( "TableName" )
on error &lcOnError
if lnRetVal < 1
   ** something bad happened
   return
endif
However, this effectively end any ability to log and process any errors. If you do not care why this method failed, then this could be a workable solution for you.

>I am using VFP 6 on 9x & 2000 machines. I designed a component GetKey that exposes a method GenKey designed to return Primary Key integers for my tables to use. I have setup an error routine to display errors I catch by calling the standard error method (that I modified) to trap -1 errors. I wish to be able to return to the calling program from that routine. I tried RETURN TO MASTER and I tried scanning the PROGRAM() programs and returning to Formxxx.Add but both failed. It kept returning to the next line in the local method.
>
>
>So, here is the scenario:
>
>Form1 is running its Add method.
>
>That method calls Form1.cstGetKey.GenKey( "TableName" ) where tablename is the name of the table to generate a key for.
>
>Somewhere in the middle of the routine an error occures causing Form1.cstGetKey.Error(-1,mymessage,0) to fire.
>
>From there I want to return to Form1.Add() without further execution of the GenKey method. This shouldn't be a problem but I must be dense because I can't find the solution.
>
>Thanks in advance
>
>Terry
Mark McCasland
Midlothian, TX USA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform