CodedK
asked on
Integer overflow problems
Hi.
I have a project with many calculations inside some timers.
After some seconds (~ 90000, almost a day) it pop up a message sayint "integer overflow"
and i have to terminate the program.
I've turned on Overflow checks in Options ---> Compiler.
I've put this line at the beggining : {$OVERFLOWCHECKS ON}
-------------------------- ---------- ---------- ---------- ---------- ----
In EVERY calculation i've put :
TRY
....
.... CODE GOES HERE
....
....
Except on Exception do
begin
Timer1.Enabled:=False;
Timer2.Enabled:=False;
Timer3.Enabled:=False;
Timer4.Enabled:=False;
ErLog:=tStringList.Create;
ErPath:=ExtractFileDir(Par amstr(0));
ErLog.Add('Error in "Section 1"');
ErLog.SaveToFile(ErPath+'\ ErrorLog.t xt');
Application.Terminate;
end;
end;
(variables ErLog:TStringList; ErPath:String;)
BUT the program does NOT create an error log. It gives the error messages again and again.
It bypass the try ...except as it seems....
I tried to run the program from delphi with timer interval 1msec and let it run for 2million times !
No error. I can reproduce the error and i dont know how to find it.
Can you help ?
Thanks in advance.
I have a project with many calculations inside some timers.
After some seconds (~ 90000, almost a day) it pop up a message sayint "integer overflow"
and i have to terminate the program.
I've turned on Overflow checks in Options ---> Compiler.
I've put this line at the beggining : {$OVERFLOWCHECKS ON}
--------------------------
In EVERY calculation i've put :
TRY
....
.... CODE GOES HERE
....
....
Except on Exception do
begin
Timer1.Enabled:=False;
Timer2.Enabled:=False;
Timer3.Enabled:=False;
Timer4.Enabled:=False;
ErLog:=tStringList.Create;
ErPath:=ExtractFileDir(Par
ErLog.Add('Error in "Section 1"');
ErLog.SaveToFile(ErPath+'\
Application.Terminate;
end;
end;
(variables ErLog:TStringList; ErPath:String;)
BUT the program does NOT create an error log. It gives the error messages again and again.
It bypass the try ...except as it seems....
I tried to run the program from delphi with timer interval 1msec and let it run for 2million times !
No error. I can reproduce the error and i dont know how to find it.
Can you help ?
Thanks in advance.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ciuly can you explain more about the sizes.. What do you mean by size mismatch?
Thanks.
Thanks.
well .. when you have operands of some type and result is anotehr type.
ex:
byte*byte = word
but if you do byte = byte*byte you have a type size issue as byte*byte will not fit in a byte.
until we figure it out, install madhis madexcept. compile with debug info and all that, and that catch the exception like that (maybe it's not an exception but an error, in which case a simple catch exception deosn't help)
let the app run until it booms.
I'll try to think of other reasons that could cause an integer overflow in the OS as this is probably not delphi issue.
ex:
byte*byte = word
but if you do byte = byte*byte you have a type size issue as byte*byte will not fit in a byte.
until we figure it out, install madhis madexcept. compile with debug info and all that, and that catch the exception like that (maybe it's not an exception but an error, in which case a simple catch exception deosn't help)
let the app run until it booms.
I'll try to think of other reasons that could cause an integer overflow in the OS as this is probably not delphi issue.
you can also try with unsigned if you don't require -ve numbers
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Another thing you could try is using 'try .. except .. end' for whole app instead of using it only for calculations (just in case if u get overflow somewhere else).
Project -> View Source -> ...
begin
try
Application.Initialize;
Application.CreateForm(TFo rm1, Form1);
Application.Run;
except
// save log
end;
end.
Project -> View Source -> ...
begin
try
Application.Initialize;
Application.CreateForm(TFo
Application.Run;
except
// save log
end;
end.
And one more thing - do not use "compile and run" for testing "try .. except" stuff. Run an app without involving Delphi (or disable debugger before running an app from Delphi).
ASKER
Thanks Zhaawz.
I'll give it a try without on Exception to see if it can create the log.
I'll give it a try without on Exception to see if it can create the log.
ASKER
Thank you all for your help and sorry for the delay.
I've searched thoroughly the code to find errors. I didnt found any...
So i've replaced all integers with Int64 and the error didnt occur...
This is half measure but at least the app is running fine.
Though i cant understand why it doesnt go in the try...except when the error occur.
I will split points equally and accept atul_parmar suggestion.
Thank you.
I've searched thoroughly the code to find errors. I didnt found any...
So i've replaced all integers with Int64 and the error didnt occur...
This is half measure but at least the app is running fine.
Though i cant understand why it doesnt go in the try...except when the error occur.
I will split points equally and accept atul_parmar suggestion.
Thank you.
ASKER
(only a depricated command at some point BUT i've used it since the version 1
of this project without any problems).
Before i post this question i was reading that article :)
I've placed everywhere "*1.0" in multiplications. I did everything the article says.
Atul_parmar thank you, of course i know that, i could replace int with int64 but this would make the app,
use TOO much memory.
And i dont assign big values (2 or MAX 3 digits) and in every tick of the timer they turn to zero.
I'm trying to reproduce the problem by running the program from Delphi 7,
I've tried with interval '1 sec' (as it is) and let it run for 2 days.
I've tried with interval '1 msec' and let it run for 15 hours (15.000 hours of calculations in real life)
BUt there was no problem.
When i run the program from windows then at some point ~80.000 - 90.000 seconds (1 day)
there is that integer flow message popping up every second.
The problem is WHY it bypass the TRY... EXCEPT ?
Thanks for your help.