divide by zero - nasty crash

Archives Forums/BlitzMax Bug Reports/divide by zero - nasty crash

slenkar(Posted 2009) [#1]
Local the_int=0

Local x=1/the_int

Print x


there is no warning message when running this program,
it took me a few hours to track down why my game was crashing on windows
due to a mistake I was dividing by zero.
Is this just something we have to look out for? or is it a bug that it doesnt highlight the offending line and provide an error message instead of just crashing?


GIB3D(Posted 2009) [#2]
Usually I just use a floating point number and it doesn't give me any error.

Local the_int=0

Local x=1.0/the_int

Print x



But of course I use Blitz3D so I don't know if it works with BlitzMax.


r(Posted 2009) [#3]
@ GIB3D = on blitzmax no errors but the result is :-2147483648


_Skully(Posted 2009) [#4]
Always ensure you don't get a divide by zero... always


Brucey(Posted 2009) [#5]
Interesting, on my Mac I get the crash console reporting :
Exception Type:  EXC_ARITHMETIC (SIGFPE)
Exception Codes: EXC_I386_DIV (divide by zero)
Crashed Thread:  0  Dispatch queue: com.apple.main-thread


I'm pretty sure that BlitzMax used to throw a runtime exception in debug mode rather than crashing out like this.


GfK(Posted 2009) [#6]
Always ensure you don't get a divide by zero... always
I'm fairly confident he didn't put the error in his code on purpose - he's simply saying that the lack of a runtime error made it nigh on impossible to track down.

My line intersection code (code arcs) had a divide by zero problem at first but it didn't crash - it just printed an unexpected result. I wonder if its OS specific? I wrote it under Windows 7 I think.