Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can the global error handler be called via TRY-CATCH
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01235566
Message ID:
01235804
Vues:
20
This message has been marked as the solution to the initial question of the thread.
>Hi all
>
>Is there a mechanism to escalate the error to the global error handler if not handled by the TRY-CATCH. Or do we have to call the global error handler manually?

You can rethrow an error in the Catch and that will promote up to a higher level error handler (including ON ERROR) but if you do that you'll loose the original error information (which is lost on the Catch).
clear
ON ERROR do ErrorHandler

TRY 
 EVALUATE("Garbage")
CATCH TO loException
	? "Exception caught"
        THROW    && Rethrow original exception

        *** Or Fail again - 'outside' error handler fires
	*EVALUATE("More Garbage")
ENDTRY

FUNCTION ErrorHandler
? Message()
? Message(1)
WAIT WINDOW "Error Handler called"
RETURN
Of course you can also fire the error handler directly and pass the exception. The problem is that unlike a traditional error handler the error information you'll retrieve when you throw out of the CATCH block is not the same as it would be if there was no try catch.

That's one of the issues with TRY/CATCH - unlike ONERROR or even class Error handlers, Try Catch unwinds the call stack so you lose the ability to easily track the code that caused the error because when Catch actually fires you're already out of that call context.

Try/Catch does:
code
   calls code
      calls code
catch error
where Error methods do:
code
   calls code
      calls code
          error method 
      calls code  (following code where error occurred)
The same applies with OnError which also is basically stacked ontop of the existing call stack.

In Web Connection when I redesigned for TRY/CATCH with version 5.0 this caused some grumbling with some folks who were very happy with the fact that their class level error handlers could collect all sorts of useful error information from the current state and that no longer works (well, there's a work around to do things the 'old' way but it's ugly).
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform