VFP Revert ON ERROR

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!
formadmirerAsked:
Who is Participating?
 
pcelbaCommented:
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
 
pcelbaCommented:
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
 
Olaf DoschkeSoftware DeveloperCommented:
Nothing to add. Go for TRY..CATCH. Your temporary error event code goes into the CATCH block.

Bye, Olaf.
0
 
formadmirerAuthor Commented:
Just did it with TRY...CATCH and love it. Never used it before. Much nicer, cleaner and easier to use - thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.