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:
01661177
Views:
60
Yes, I see it now.

>That all seems like you're not using TRY/CATCH properly.
>
>This should illustrate:
>
>
>ON ERROR DO ErrorHandler
>
>loValue = "NOT SET"
>TRY
>   loValue.Bogus()
>CATCH
>  ? "Catch"
>FINALLY
>   ? "Finally"
>ENDTRY
>
>RETURN
>
>FUNCTION ERRORHANDLER
>? "On Error Handler"
>ENDFUNC
>
>
>This will not fire the ERRORHANDLER and only fire the CATCH block. If you have an error inside of the CATCH block (ie an error in the error handler) THEN the ON ERROR handler will kick in.
>
>You need a CATCH in order for TRY/CATCH to do anything. If you don't want to have anything happen if caught just leave the code for the CATCH block blank.
>
>+++ Rick ---
>
>
>
>>>>Hi,
>>>>
>>>>Do I understand correctly that if there is an error (typo or undeclared variable or whatever problem) within TRY/CATCH, the global ON ERROR DO MyErrorHandler() will catch it? That is, that TRY/CATCH is not "isolated" from the global error handling.
>>>>Please let me know if I am correct. Or, if I don't understand it correctly.
>>>>
>>>>TIA.
>>>
>>>You understood it wrong. A Try/Catch isolates the error from outside block (silences the error if you do nothing in CATCH). You can make the error available to outside block by using THROW in catch. ie:
>>>
>>>
>>>On Error Do errHandler
>>>Try
>>>	? "A"+15
>>>Catch To oErr
>>>	*	m.oErr.UserValue = "Error caught with catch."
>>>	Throw
>>>*	Throw "Error caught with catch."  && This is not the same thing
>>>Endtry
>>>? m.newVar
>>>On Error
>>>
>>>Procedure errHandler
>>>	? "Error: [["+Message()+"]]"
>>>Endproc
>>>
>>>
>>>PS: Personally I prefer using On Error. Try Catch is not as powerful IMHO, doesn't catch every error that ON ERROR catches for example.
>>
>>What about this code:
>>
>>ON ERROR do MyError
>>
>>TRY 
>>IF adfasdfa
>>ENDIF 
>>ENDTRY 
>>=MESSAGEBOX("End")
>>RETURN 
>>
>>FUNCTION MyError
>>MESSAGEBOX("Error happened")
>>
>>
>>The MessageBox with error shows when IF with undeclared variable is used. Do you see what I am seeing?
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform