Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Understanding Try Catch
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01661136
Message ID:
01661374
Views:
83
THROW is somewhat analogous to the ERROR command - it creates a FoxPro error that behaves just like an error that was thrown because of an invalid operation.

If you issue THROW within a CATCH without a parameter it re-throws the original error which means it's as if you didn't handle the exception. That's useful if you want to log or do some other sort of work based on the original error but then want to let something higher up the call stack handle the original exception (like a logging framework or a global ON ERROR handler or application level TRY/CATCH). You can also THROW with a new exception that you create - so you can intercept an original exception, then create a new one with a more precise error message than THROW that.

THROW does have a problem though with ON ERROR handling in that the error message isn't properly accessible in AERRORINFO() which is why I usually just use ERROR instead when I want to explicitly create an error.

Why would you ever throw an error? Here's an example: In Web Connection I have a REST Service where an error automatically generates error JSON responses. So if I want to indicate a validation error or invalid input or something along those lines I can just THROW/ERROR a custom message, which will then be rendered into an error result that the client application can pick up and use. This same approach can also be used in local applications where the error can serve as a sort of messaging mechanism for known errors that need to be displayed in the UI.

+++ Rick ---


>The one aspect I do not understand well is the THROW command - the help docs are light on this and the feature came out after the Hackers guide (I am guessing as no reference in it).
>
>Can anyone give an example or explain further? In the framework I am using (VMP), they use ON ERROR as the top level error handler (and I cannot change this). Would I use THROW to pass something up to that error handler?
>
>Thx.
>Albert
+++ 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?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform