Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Understanding Try Catch
Message
 
 
To
13/07/2018 08:00:02
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01661136
Message ID:
01661165
Views:
49
>>>>>
>>>>>Errors silenced by TRY ... ENDTRY are hardest to find IMHO. Instead of silencing handle them ( sometimes they may be silenced on purpose ).
>>>>
>>>>Ok. In my view TRY ENDTRY does not silence the error (without CATCH) since ON ERROR is fired. IMHO if the TRY-ENDTRY were completely isolate the problem (silence it), the ON ERROR would not fire.
>>>>But as long as I understand how it works, it is fine.
>>>>
>>>>Update. I want to be sure you don't think I am arguing with you - you know VFP much better than me. I agree with what you said that TRY ENDTRY silences the error (undeclared variable). But another error handler is catching it and to me it means that the error was not ignored completely. That is, it was not silenced. In fact, I admit, I used to think that TRY - ENDTRY will completely isolate the error. That is, if I write any kind of JUNK code within TRY ENDTRY, the user will never see it. And I was wrong. This is all I wanted to confirm.
>>>
>>>But why would you ever have TRY without CATCH?
>>>
>>>Tamar
>>
>>I have many places in my app where I want to log a certain event (for testing or an audit). This is done by calling Strtofile() function to update a .log file. I didn't care if it was successful, for whatever reason (e.g. if the drive was not accessible) and didn't want to alert the user of the problem. So, by mistakenly thinking that TRY-ENDTRY will silence the error, if it happens, I used the TRY - ENDTRY around all of these places where I was writing the log. What happened a few days ago is that there was an error in the STRTOFILE() where I was trying to log a value of a global object. And the global object was not yet instantiated. And I saw the error in the global error handler. Made me think and I discovered how it really works. So, now, whenever I do the TRY ENDTRY (for these "insignificant" case), I will add CATCH without anything. And this will truly silence the problem. And I thought that at this point of my career I knew absolutely everything about VFP - Joking :)
>
>You write "around all of these places where I was writing the log", Why don't you simply create ONE method which does the logging for you? Then you can call this method whenever you want to add something to the log.

Because the logs are different, names, what is stored, etc. Although I agree with you that I will benefit by creating a generic function to write a log. And simply pass the file name and what to log to the generic function. The key is still that I now understand that with this "generic" log I have to be careful with TRY - ENDTRY (that is, to include catch), so that something goes wrong, it won't fire the global error handler.
Thank you.
"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