What is the use of Try? It is allowing an error ?
Posted
#1
(In Topic #1290)
Regular

How to use Try and what is the need if the real catch occurs without Try
Code
Try re = New RegExp(Mix, newPatt, CompOpt, ExecOpt)
Return re
Finally
Message.Error("Fin: Pattern inválido, verifique")
Catch
Message.Error("Cat: Pattern inválido, verifique")
End
Posted
Guru

TIP: - To get nice looking code below use the 'gb' button not the '</>' button
If the file does not exist, a warning is given, otherwise the text in the file is printed.
Posted
Guru

If you do not use "Try" then the Finally and Catch statements are used as expected.
using Try is for suppressing the normal error management. any error can then be detected yourself by checking "Error" (as Cogier has shown) but an error will not be raised, that's the point of "Try"
it can also be useful for just suppressing errors and can make for faster code. like these 2 statements
probably the first one is faster.
Posted
Regular

thanks 2 both guys
Posted
Regular

I DID like it lol
Posted
Enthusiast

and : Finally and Catch are for a block of code
Or have I interpreted it wrong ?
Posted
Regular

What I know:
Try "tries" to supress the error and you can treat (If you want) checking state of Error. Useful to ignore "not important" errors.
Catch will only work if there is not a try above (tell me if I am wrong)
Finally must be used before catch because it can raise another error
Posted
Guru

If Finally is used it must be used before Catch
Posted
Regular

sergioabreu said
Catch will only work if there is not a try above (tell me if I am wrong)
Not exactly true. Catch will work if an Error is detected on any line that is not "protected" by a Try.
Posted
Regular

Having
, the Catch in a line below below will not catch THAT ERRORa Try protecting the code that would produce the error
Code
Try line that could generate error
Catch do not catch
Posted
Regular

thatbruce said
sergioabreu said
Catch will only work if there is not a try above (tell me if I am wrong)
Not exactly true. Catch will work if an Error is detected on any line that is not "protected" by a Try.
"That is ABOVE the Catch line"
Posted
Regular

Unless…
There is a top level error handler, I can't remember how it is used?
Posted
Regular

sergioabreu said
It results the same:
Having, the Catch in a line below below will not catch THAT ERRORa Try protecting the code that would produce the errorThat's what I meant. A Try just aboveCode
Try line that could generate error
Catch do not catch
Exactly! THAT line is "protected" which means the interpreter ignores any error that occurs when it is executed. Perhaps you are thinking that TRY is working as a block definition. It isn't, it applies to a single line of code. Similarly CATCH and FINALLY aren't blocks either, they are sort of goto targets. If an error is detected in a non-TRY line and there is a CATCH "label" then the interpreter does a jump to the first line in after the CATCH label.
IOW if an error occurs in an unprotected line then execution immediately jumps to the CATCH, nothing in between is executed.
Theoretically, when executing the CATCH code reaches its end, execution should then jump to the FINALLY and execute that code and then RETURN. But I have doubts about that.
<COLOR color="#FF0000">No, that's wrong. The FINALLY chunk is executed before the CATCH chunk.</COLOR>
Posted
Regular

1 guest and 0 members have just viewed this.


