Page 1 of 1

A native Assert function

Posted: Tue Jun 09, 2009 12:11 pm
by milan1612
I really like the idea of having a native Assert function. The signature could look something like this:

Code: Select all

Assert(SizeOf(Integer) = 4)
Assert(OpenWindow(0, ...) <> 0)
Assert(*Ptr <> 0)
The assertion should be tested during compilation (where possible) and during runtime.
If the assertion failes, an error dialog should be displayed showing the exact location in the code,
and maybe some other information followed by an immediate call of the End function.

Would be very handy to develop much more reliable code in Purebasic :P

Posted: Tue Jun 09, 2009 12:47 pm
by Fred
The 'much reliable' stuff is out of context, as it's not a limitation to not have such simple macro build-in. And some (like me) hates the assert way to not be able to recover or finish properly in case of runtime errors.

Posted: Tue Jun 09, 2009 12:53 pm
by milan1612
Of course I can write my own macro for this and the lack of an Assert macro in
Purebasic is certainly not a limitation. It's just that I always prefer it the "native way"
so I don't need to roll up my own stuff :P. Well, fair enough...