RuntimeError command
Blitz3D Forums/Blitz3D Programming/RuntimeError command
| ||
I am trying to build a mesh library and almost in every function I check for the existence of an argumentFunction MyFunction(t.MyType, ...) if t = Null then RuntimeError "MyFunction: t does not exists!" : Return . . . End Function I am wondering if this practice is a bottle neck to the execution speed. On the other hand I think it is not right to build a library without error check. |
| ||
I would do:Function MyFunction(t.mytype) if t <> null ;do stuff with t endif end function In other words - error checking, yes. Pointless error messages that ultimately nobody will see, no. Also, nothing after RuntimeError will get executed, so the Return is redundant in this case. |
| ||
I don't think you're checking the existance of an argument this way, but simply if it is zero. You can only use an argument optionally if you declare a default value: function test(a=0) But if you really want to test if an argument is used,you maybe have to set the default to a value that makes absolutely no sense and is completely unlikely to be used, eg: function test(a=$FEFEFEFE) if a=$FEFEFEFE then ; no argument was received This example makes sense if the value will always be in a lower range. Right now I have no idea how to handle this savely if the entire 32 bit range should be usable. |
| ||
GfK: if you return with a Null t you have to face it later in the program flow... jfk EO-1110: Checking a pointer to see if it is zero the you get an "Illegal type conversion" from Blitz3D I am still wondering if its worth error checking within every function in a library... |
| ||
Yes Moraldi that is good practice. I almost always do it. I usually have a DEBUG constant that I turn off when I build the EXE. Function MyFunction(t.MyType, ...) If DEBUG If t = Null then RuntimeError "MyFunction: t does not exists!" . . . End Function |
| ||
Total overkill in my opinion but probably good practice to have all this kind of error trapping. Surely you know immediately if your passing a duff type to a function? Stevie |
| ||
Surely you know immediately if your passing a duff type to a function? Nah, sometimes you have like: Function MyFunction(t.MyType, ...) unit\target=t Endfunction then somewhere else you find out unit\target=null Basically things can get complicated before you ever try to actually use the null instance. |