[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TestError


Try (😉) thinking this way...

"TRY" disengages the global error handling mechanism for a short time (see later). It will allow a command that would/could cause a generic error to be raised to proceed to the next command without an error "bang" to happen. So... we can test the Error boolean flag and do something if or otherwise. Suppose there is an infamous cat in a box, now we don't know if it does or does not exist do we? So attempting to determine at command line #1,

	01  If ThisCat.Exists then ...

 is indeterminate UNTIL the line is executed. Since ThisCat doesn't exist, (ThisCat = Null) then ThisCat.Exists would fail with a null object error and the normal error handling would be invoked. But if we

	01 Try ThisCat.Exists
	02 If Not Error then
	03	DoSomethingEvilToTheCat
	04 Else
	05 	CloseBox 	
	06 EndIf

then depending on Error the cat in question will have some bad luck or we just close the box until next time.

Global error handling...

is a bit different, lets face it life is bad. Stuff happens. Phone operator A deletes your account while you are talking to phone operator B, etc etc. Life on planet Gambas is a lot more logical. Something happens and suddenly something else doesn't work. And no-one expected so. Error.Bang! = true

What the interpreter does is this (sort of).

It looks at the current method block to see if there is a Catch "label". If so then it jumps there and does whatever it says. Fine, but if there is none it crawls its way majestically up the call stack looking to see if there is anyone that can do something about this deplorable lack of knickers. If no-one can then the runtime has a bit of a panic and throws up (raises a system error).

Important! Finally, there is a thing called Finally. Everybody in the call stack can have a Finally block, sort of like famous last words. No matter if the object was about to expire from the dreaded dividebyzero cancer, it will have its famous last word(s). These will issue no matter how hard you try to strangle him beforehand.

I'd better go now. 😅

b


References:
TestErrorCD <dessere.claude@xxxxxx>
Re: TestErrorBruce Steers <bsteers4@xxxxxxxxx>
Re: TestErrorCD <dessere.claude@xxxxxx>
Re: TestErrorBruce Steers <bsteers4@xxxxxxxxx>
Re: TestErrorCD <dessere.claude@xxxxxx>