Munair wrote: ↑Feb 09, 2022 11:25
As of QuickBASIC 7.1 PDS there was ON LOCAL ERROR GOTO for use in procedures but I don't remember the details. From the FB manual I understand that fbc supports but ignores the LOCAL clause. I haven't actually used it in FB.
Global on goto as a catch all is fine for small potatoe batch stuff. However it is no substitute for exceptions.
The easiest way to imagine the use of exceptions is a long running server like a webserver. Such application have a hardened core somewhere that handles the requests, and calls business code to process them and generate response pages.
Now, not all codepaths of that business code run very often, and you when you encounter an inconsistency you just want to abort.
But the call chain nesting might have descended already several levels, and each level potentially has to do things to restore the status quo to not leave memory leaks or corrupt other state. Some of them might be much used code, some less.
This is what the various do catch and finally stages do. Rewind state on an "special" even so that the long running application can go on without losses. Without manual "asm ret" tuning.
Now try to imagine implementing something like that with a global "on error goto". I might be missing something, but IMHO this is not the same thing.
jj2007 wrote: ↑Feb 09, 2022 12:10
Code: Select all
print "Hello World"
Dim lptr as any ptr
if 0 then
label1:
asm mov dword ptr [lptr], offset label1
print "this is label 1 at ";lptr
asm ret
endif
asm call label1
print "that was cute"
Sleep
Calling a line label works perfectly, in 32- and 64-bit FB, but I have no idea where and why it could be useful.
Same for ON ERROR GOTO. Occasionally, I use a
Try...Catch...Finally construct, but I must be a bit desperate to do that; in 99% of all cases, avoiding errors before they throw an exception is the far better alternative.
See above. While doing an assembler call and matching ret, is a fun experiment, it is in no way a substitute of exceptions which allow a piece of code to handle fixing state (program state but also e.g. allocations, closing files etc) locally when somewhere deeper the call chain aborts with an exception.