?
Solved

VFP Revert ON ERROR

Posted on 2012-09-19
4
Medium Priority
?
566 Views
Last Modified: 2012-09-19
Hi all - quick question...

How do I capture the current ON ERROR so that I may temporarily assign a new ON ERROR event and then revert to the original?

Thanks!
0
Comment
Question by:formadmirer
  • 2
4 Comments
 
LVL 43

Expert Comment

by:pcelba
ID: 38415647
You may use ON() function:

LOCAL lcOnError
lcOnError = ON("ERROR")
*-- Suppressing the ON ERROR behavior
ON ERROR *

STORE tertewr TO ryeuirweiru  && This command should not generate error

*-- Restoring the previous setting
IF EMPTY(m.lcOnError)
  ON ERROR
ELSE
  ON ERROR &lcOnError
ENDIF

Of course, if some outer TRY - CATCH is active or if you are in an object then the error may be captured by another method.
0
 
LVL 43

Accepted Solution

by:
pcelba earned 2000 total points
ID: 38415669
The better way how to suppress ON ERROR bahaviour is to enclose your command in TRY - CATCH structure (you don't need any restoring etc.):

TRY
  STORE tertewr TO yeuirweiru  && This command should not generate an error
CATCH
  *-- The program flow goes here
ENDTRY

TRY - CATCH works under almost all conditions and it is more robust than ON ERROR.
0
 
LVL 30

Expert Comment

by:Olaf Doschke
ID: 38415746
Nothing to add. Go for TRY..CATCH. Your temporary error event code goes into the CATCH block.

Bye, Olaf.
0
 

Author Comment

by:formadmirer
ID: 38415791
Just did it with TRY...CATCH and love it. Never used it before. Much nicer, cleaner and easier to use - thank you!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
LinkedIn blogging is great for networking, building up an audience, and expanding your influence as well. However, if you want to achieve these results, you need to work really hard to make your post worth liking and sharing. Here are 4 tips that ca…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question