KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Range checking
PRODUCT: 4D | VERSION: | PLATFORM:
Published On: April 23, 1999
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

Technical Support will sometimes receive a complaint from a customer that their database is crashing. More often it is something specific to code within a compiled database which is causing this problem.

One way to help determine if there is a problem with the code is to use a feature of the 4D Compiler called Range Checking. This allows a message to be displayed to the user that an error occurred, rather than crash the computer.

Examine the following code segment:

ARRAY STRING(10;asNames;5)
asNames{1}:="Gerald Bailey"
asNames{2}:="Raymond Manley"
asNames{3}:="Thomas Durso"
asNames{4}:="Guy Howe"
asNames{5}:="Ruffin Scott"
asNames{6}:="Tim Tonooka"

Here you can see two problems with this code. First, there are only 5 elements in the array and the code addresses six. Second, the string length is set to ten, and there are items longer than ten characters.

If you were to compile this database and then execute the above method, you would find that it will crash your computer when range checking is turned off. If you turn on range checking, you will get a message that reads:


A runtime error occurred at line number: 3
When executing the method:
METHOD1
The destination string is smaller than the source.


Is there anything wrong with the syntax of any of the lines of code? No.
Is there anything wrong with the logic of the lines of code? Absolutely!

The 4D Compiler does not check that your code is logical, only the syntax. This is why the code will compile just fine, but cause a crash when it is executed.

The following is a true story:

Customer: My database is crashing.
TS Rep: Is your database compiled?
Customer: Yes.
TS Rep: Is range checking turned on?
Customer: No.
TS Rep: Can you turn it on, recompile and then test it?
Customer: No. When range checking is turned on, my users see error messages on their screen. I don't want them to see the error messages.

Although this makes for a funny story, it does show a problem with the code in the database rather than a problem with the 4D software. Once you've used the software for some time and performed many tests, then perhaps it may be safe to turn range checking off. But until then, better safe than sorry....