Closed GWRon closed 1 year ago
I've always understood that release builds didn't do bounds checking.
No bounds check == no exception to catch. Am i misunderstanding the issue?
Yes. But also null accesses are not catched.
What should be "catchable" in release builds then / for what could try/catch be used there?
The OOB array access will not throw because there is no bounds checking in release mode. This has always been the case.
If you don't know at runtime whether you are likely to be trying to access outwith the bounds of an array, you should design your program to stay within those bounds. The same applies to attempting to use null objects.
I still would like to know what the try catch ...is able to catch. Throw-new-exception-stuff only?
That an array access on its own does no boundary check and blindly tells what it is told to do... I kinda knew that but yeah, dunno what try/catch changes behind the scenes.
Feel free to reply to the syntaxbomb thread too.. so I do not have to relay the "solution" to Adam's question/issue.
I still would like to know what the try catch ...is able to catch.
Anything object that's thrown. But the brounds check that would throw the exception simply isn't included in release builds.
The bbdoc comments on the exception types in blitz.mod/blitz.bmx
mention this. TArrayBoundsException, TNullObjectException, TOutOfDataException and TInvalidEnumException are only thrown in debug mode to make it easier to find errors in your code. There is nothing special about those types themselves, if you want you can throw and catch them like any other. It's just not a good idea because that's not what they're for, they're supposed to never happen in a bug-free program. (That goes for the other exceptions in blitz.bmx
too, e.g. don't catch a RuntimeError
.)
I linked that issue in the SB thread so I guess this helps Adam already.
Using Adam Novagen's code from there: https://www.syntaxbomb.com/blitzmax-blitzmax-ng/legacy-have-i-completely-misunderstood-exceptions/new/#new
The following code is created with NG...
in debug builds:
and in release builds:
So both contain
bbExTry
and friends - but only the debug build actually throws the error. Release builds simply printhere (so do not catch the out-of-bounds-error). If I added a
into the Try-Catch block, then it segfaults (so the null access is also not catched).
Expected behaviour: I guess it should be able to try/catch it ... or if this should only work in debug builds, then it should not emit the C code for try/catch stuff.