Error Trapping

Blitz3D Forums/Blitz3D Beginners Area/Error Trapping

Ace Killjoy(Posted 2008) [#1]
Does anyone know of some good techniques for "error trapping"?
Sometimes I have problems with collisions and recently it has been brought to my attention that I should put some of the stuff in my code.


GfK(Posted 2008) [#2]
For a start:
x = LoadMesh("model.x")
If Not x
    RuntimeError "File missing"
EndIf



Ace Killjoy(Posted 2008) [#3]
I will have to study that one.


Knight #51(Posted 2008) [#4]
It's really simple:



Hope that helped =)


Ross C(Posted 2008) [#5]
To expand on that, when ever you load an entity, sound or image or most external media, it returns an integer number, i suppose it would be a memory location of the stored media. Any number really, except zero, would mean a successful load. So, therefore by checking for zero, your determining if it was loaded.


Knight #51(Posted 2008) [#6]
it returns an integer number, i suppose it would be a memory location of the stored media.


The handle to the _____ is a memory address to the _____.


Ace Killjoy(Posted 2008) [#7]
Ok.
Sometimes I've noted that it says "Entity Does Not Exist" and points to the line where the handle is first called, when it is actually failing to load the file itself.
I'm not quite sure how this RuntimeError command will help much (except for customization).
Anything else I should know?


Knight #51(Posted 2008) [#8]
Sometimes when it says "Entity Does Not Exist", it usually means that you didn't make the loaded entity "Global". Which is highly recomended that you do.


Ace Killjoy(Posted 2008) [#9]
Yah, I'm starting to do that more.


Knight #51(Posted 2008) [#10]
cool-beans


Warner(Posted 2008) [#11]
You could intercept the error by supplying some alternative media:
x = LoadMesh("model.x")
If Not x
    x = CreateCube()
EndIf

However, that still doesn't catch all errors. If a surface contains too much vertices, you'll get a memory access violation, which I believe can't be trapped.

I think a good way of handling errors is to place every routine that could generate an error in a Function. You can then apply the error checking inside the function. Ie:
Function MyMoveEntity(ent, x#, y#, z#, global=0)

   if (ent <> 0) then MoveEntity ent, x, y, z, global

End Function



Knight #51(Posted 2008) [#12]
Good idea Warner, but that would take a while......unless you just include all of those custom functions in an 'include' file. Then just re-use them.