It seems that division by zero is not caught by VFP. In the command window, type ? 1/0 <return>, and you get a line of asterisks, right? (I'm running VFP9 SP2.)
I have a form which evaluates a string expression and sends the result back to its caller. The only way I have found to catch division by zero is in a form method like this:
LOCAL loEx As Exception, lnTmp As Double
*!* THIS.cExpr is entered into an edit box on the form, THIS.nRetVal is the form return value
loEx = .NULL.
TRY
THIS.nRetVal = EVALUATE(THIS.cExpr)
lnTmp = 1/THIS.nRetVal
= MOD(THIS.nRetVal, lnTmp) && catches error 1307
CATCH TO loEx
ENDTRY
IF ISNULL(loEx)
THIS.Release()
ELSE
THIS.HandleException(loEx)
ENDIF
I think it wrong that VFP does not catch this error natively, unless I've missed a SET command or SYS() function.
Any thoughts people?
Laurie Alvey
--- StripMime Report -- processed MIME parts ---
multipart/alternative
text/plain (text body -- kept)
text/html
---
_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/1376299105.95892.YahooMailNeo@web87903.mail.ir2.yahoo.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
On Mon, Aug 12, 2013, at 10:18 AM, L ALVEY wrote:
> I think it wrong that VFP does not catch this error natively, unless I've
> missed a SET command or SYS() function.
Well, it has ever been thus, and probably remained thus because that's
how dBase worked back in the mists of time.
I have to say personally it has never been an issue - if there's ever a
situation where it could conceivably happen you have to cater for it in
code.
_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/1376299433.14287.8752179.6076BCC3@webmail.messagingengine.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Author: Man-wai Chang
Posted: 2013-08-12 07:42:57 Link
If TRY... CATCH doesn't work, you could always use the good old ON ERROR.
On Mon, Aug 12, 2013 at 5:18 PM, L ALVEY <trukker@btinternet.com> wrote:
> It seems that division by zero is not caught by VFP. In the command window, type ? 1/0 <return>, and you get a line of asterisks, right? (I'm running VFP9 SP2.)
--
.~. Might, Courage, Vision. SINCERITY!
/ v \ 64-bit Ubuntu 9.10 (Linux kernel 2.6.39.3)
/( _ )\ http://sites.google.com/site/changmw
^ ^ May the Force and farces be with you!
_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/CAGv=MJB8vwr6bDOMTsOn-Ug+d2q+W9051eTsPYrGDMJxEyVkAA@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
ON ERROR doesn't work either.
Laurie Alvey
________________________________
From: Man-wai Chang <changmw@gmail.com>
To: ProFox Email List <profox@leafe.com>
Sent: Monday, 12 August 2013, 13:42
Subject: Re: FP: Trapping division by zero (Error 1307)
If TRY... CATCH doesn't work, you could always use the good old ON ERROR.
On Mon, Aug 12, 2013 at 5:18 PM, L ALVEY <trukker@btinternet.com> wrote:
> It seems that division by zero is not caught by VFP. In the command window, type ? 1/0 <return>, and you get a line of asterisks, right? (I'm running VFP9 SP2.)
--
.~. Might, Courage, Vision. SINCERITY!
/ v \ 64-bit Ubuntu 9.10 (Linux kernel 2.6.39.3)
/( _ )\ http://sites.google.com/site/changmw
^ ^ May the Force and farces be with you!
_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/CAGv=MJB8vwr6bDOMTsOn-Ug+d2q+W9051eTsPYrGDMJxEyVkAA@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
--- StripMime Report -- processed MIME parts ---
multipart/alternative
text/plain (text body -- kept)
text/html
---
_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/1376313705.16353.YahooMailNeo@web87904.mail.ir2.yahoo.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
On Mon, Aug 12, 2013, at 02:21 PM, L ALVEY wrote:
> ON ERROR doesn't work either.
>
No, it's not regarded as an error or exception so the only thing that
you can do is check in code before doing a division where there's a
chance the divisor will be zero.
If you look at how various languages handle it, there is no consistent
way.
_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/1376314095.10113.8832387.140C4F1E@webmail.messagingengine.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
In fact the only time that any version of FoxPro has ever produced a
divide by zero error is back in the days of FoxPro for Windows, when
processors got so fast that the code it used internally to calculate the
speed would fail. Some enterprising hacker then hacked the support
library to stop it happening.
_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/1376316395.20974.8849995.06FCA7BA@webmail.messagingengine.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Author: Man-wai Chang
Posted: 2013-08-12 09:23:24 Link
Not even "ON ERROR *"??? Now that's weird....
>From FOXHELP.CHM:
ON ERROR DO errhand WITH ;
ERROR( ), MESSAGE( ), MESSAGE(1), PROGRAM( ), LINENO( )
*** The next line should cause an error ***
USE nodatabase
ON ERROR && restore system error handler
PROCEDURE errhand
PARAMETER merror, mess, mess1, mprog, mlineno
CLEAR
? 'Error number: ' + LTRIM(STR(merror))
? 'Error message: ' + mess
? 'Line of code with error: ' + mess1
? 'Line number of error: ' + LTRIM(STR(mlineno))
? 'Program with error: ' + mprog
On Mon, Aug 12, 2013 at 9:21 PM, L ALVEY <trukker@btinternet.com> wrote:
> ON ERROR doesn't work either.
--
.~. Might, Courage, Vision. SINCERITY!
/ v \ 64-bit Ubuntu 9.10 (Linux kernel 2.6.39.3)
/( _ )\ http://sites.google.com/site/changmw
^ ^ May the Force and farces be with you!
_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/CAGv=MJAXGqGpBFB-U_d3rGRmJCjQtyBTYxU16i=sO6+Lesv8+g@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Author: Man-wai Chang
Posted: 2013-08-12 09:27:56 Link
This is my Foxpro/DOS way of catching division by zero:
on error *
x=1/0
if if "*"$x
? x
? "divide by zero"
endif
on error
--
.~. Might, Courage, Vision. SINCERITY!
/ v \ 64-bit Ubuntu 9.10 (Linux kernel 2.6.39.3)
/( _ )\ http://sites.google.com/site/changmw
^ ^ May the Force and farces be with you!
_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/CAGv=MJBG8icTrciptu-DsJZmL7F9FW+WFP1C=Nbsd1ghx_Eg-w@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Not so, I have a select that fell over with div/0 and an on error dealt with
that.
Al
-----Original Message-----
From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of Alan
Bourke
Sent: 12 August 2013 15:28
To: profoxtech@leafe.com
Subject: Re: FP: Trapping division by zero (Error 1307)
On Mon, Aug 12, 2013, at 02:21 PM, L ALVEY wrote:
> ON ERROR doesn't work either.
>
No, it's not regarded as an error or exception so the only thing that
you can do is check in code before doing a division where there's a
chance the divisor will be zero.
If you look at how various languages handle it, there is no consistent
way.
_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/003c01ce9774$f958a5e0$ec09f1a0$@com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
I used a similar method in an earlier version of the screen which worked fine. In my form, I used the MOD() function which catches the error, as does the % operator. There is some inconsistency here in that % traps the error but / doesn't.
Thanks to everyone who contributed.
________________________________
From: Man-wai Chang <changmw@gmail.com>
To: ProFox Email List <profox@leafe.com>
Sent: Monday, 12 August 2013, 15:27
Subject: Re: FP: Trapping division by zero (Error 1307)
This is my Foxpro/DOS way of catching division by zero:
on error *
x=1/0
if if "*"$x
? x
? "divide by zero"
endif
on error
--
.~. Might, Courage, Vision. SINCERITY!
/ v \ 64-bit Ubuntu 9.10 (Linux kernel 2.6.39.3)
/( _ )\ http://sites.google.com/site/changmw
^ ^ May the Force and farces be with you!
_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/CAGv=MJBG8icTrciptu-DsJZmL7F9FW+WFP1C=Nbsd1ghx_Eg-w@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
--- StripMime Report -- processed MIME parts ---
multipart/alternative
text/plain (text body -- kept)
text/html
---
_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/1376383820.96482.YahooMailNeo@web87906.mail.ir2.yahoo.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.