Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

EZeroDivide, how to catch this exception

162 views
Skip to first unread message

Claus Lynge Christensen

unread,
Aug 4, 1998, 3:00:00 AM8/4/98
to
How do I catch the EZeroDivide exception?

I'm having troubles catching the exception illustrated in the example
below,
instead of firing the exception when evaluating :
Value := 1 / 0;
the ' Value ' evaluates to 'Inf' which I can then report as shown with the
first MessageDlg (below), however this does not handle the exception
properly and leads to problems later on. I have been runnig this type of
exception code, without any problems, is there some kind of floating point
setup that I'm missing ?
Anyone having any suggestions ?


Claus Lynge

procedure TForm1.SpeedButton1Click(Sender: TObject);
var Value:Extended;
begin
try
Value := 1 / 0;
if FloatToStr(Value)= 'INF' then MessageDlg('Floating point div
zero!!!!', mtError,[mbOK],0);

except on EZeroDivide do
begin
MessageDlg('Floating point div zero!!!!', mtError,[mbOK],0);
end;
end;
end;

Michael Burrows

unread,
Aug 4, 1998, 3:00:00 AM8/4/98
to
Claus,
I have had this problem too and I have not resolved it. One suggestion on
this newsgroup was "Try [SysUtils|System].Set8087CW (at least in D3)" I'm
using D2 and I could not find an equivalent.

Early versions of my app don't exhibit the problem. The only thing I can
think is causing it is the program size ( >10000 lines). Is your experience
similar? If you manage to solve this could you let me know please.

tak, med venlig hilsen,
Mike

JB

unread,
Aug 4, 1998, 3:00:00 AM8/4/98
to
you won't catch the exception by the code snippet you wrote. Delphi
does some optimization and assigns the INF to the value. However, I
don't think you will explicitly write in code an expression that divides
by the constant 0 (ie 1/0) as you did in your example...if you are
dividing two variables v1/v2 and v2 happens to contain the value 0, then
the exception will be raised...

JB

JB

unread,
Aug 5, 1998, 3:00:00 AM8/5/98
to
I did some more research on this...here's what I found

Integer divide,
5 div 0; // compile time error, surprising!
Floating point constant divide,
1/0; // INF assigned to result
Floating point var divide,
v2:=0; v1/v2; // Exception triggered

JB

--


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
JB Manibo
http://www.cs.csubak.edu/~mmanibo

5 out of 4 people suck at fractions.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

0 new messages