Link to home
Start Free TrialLog in
Avatar of formadmirer
formadmirerFlag for United States of America

asked on

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!
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

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.
ASKER CERTIFIED SOLUTION
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nothing to add. Go for TRY..CATCH. Your temporary error event code goes into the CATCH block.

Bye, Olaf.
Avatar of formadmirer

ASKER

Just did it with TRY...CATCH and love it. Never used it before. Much nicer, cleaner and easier to use - thank you!