Error trapping within my ON ERROR routine

Error trapping within my ON ERROR routine

Post by Ben Hambidg » Sun, 01 Apr 2001 01:25:24



I've got a single global error-handling routine. However, I'd like to
include a command in it that might generate an error. Elsewhere, the
following works:

lcOldOnError=ON("ERROR")
ON ERROR *  && Do nothing
loWord.Visible=.T.      && This will fail if loWord doesn't exist or
the link to MSWord is no longer current
ON ERROR &lcOldOnError

However, within my main ON ERROR routine, the command generates a
standard VFP error.

How can I get round this?

--
Ben Hambidge

 
 
 

Error trapping within my ON ERROR routine

Post by Alexandre Pechtchansk » Sun, 01 Apr 2001 04:46:03




Quote:>I've got a single global error-handling routine. However, I'd like to
>include a command in it that might generate an error. Elsewhere, the
>following works:

>lcOldOnError=ON("ERROR")
>ON ERROR *  && Do nothing
>loWord.Visible=.T.      && This will fail if loWord doesn't exist or
>the link to MSWord is no longer current
>ON ERROR &lcOldOnError

>However, within my main ON ERROR routine, the command generates a
>standard VFP error.

>How can I get round this?

I believe ON ERROR is disabled within ON ERROR procedure and on-line help bears
me out:

ON ERROR procedures cannot be nested. If ON ERROR is issued within an ON ERROR
procedure, the default Visual FoxPro error handler is restored.

So to work around this you should use alternative error detection mechanism,
e.g.,
IF Type("loWord") = "O"
  loWord.Visible=.T.
ENDIF

Having said this, I greatly doubt the wisdom of interacting with external
programs in error handler.  Remember KISS principle!

--
[ When replying, remove *'s from address ]
Alexandre Pechtchanski, Systems Manager, RUH, NY

 
 
 

Error trapping within my ON ERROR routine

Post by Ben Hambidg » Sat, 07 Apr 2001 22:44:54






>>I've got a single global error-handling routine. However, I'd like to
>>include a command in it that might generate an error. Elsewhere, the
>>following works:

>>lcOldOnError=ON("ERROR")
>>ON ERROR *  && Do nothing
>>loWord.Visible=.T.      && This will fail if loWord doesn't exist or
>>the link to MSWord is no longer current
>>ON ERROR &lcOldOnError

>>However, within my main ON ERROR routine, the command generates a
>>standard VFP error.

>I believe ON ERROR is disabled within ON ERROR procedure and on-line help bears
>me out:
>So to work around this you should use alternative error detection mechanism,
>e.g.,
>IF Type("loWord") = "O"
>  loWord.Visible=.T.
>ENDIF

(Sorry about delay - My ISP has only just started delivering news after
a week's gap!!)

This unfortunately will not work in all cases: it is quite possible for
VFP to return TYPE("loWord") as O, but MSWord has shut down (or the link
has been broken).

Is there any way to test if the link is still *live* and only then set
Visible to .T.?

--
Ben Hambidge

 
 
 

Error trapping within my ON ERROR routine

Post by Alexandre Pechtchansk » Sun, 08 Apr 2001 01:57:25




[ Courtesy cc'ed through e-mail to the quoted author ]





>>>I've got a single global error-handling routine. However, I'd like to
>>>include a command in it that might generate an error. Elsewhere, the
>>>following works:

>>>lcOldOnError=ON("ERROR")
>>>ON ERROR *  && Do nothing
>>>loWord.Visible=.T.      && This will fail if loWord doesn't exist or
>>>the link to MSWord is no longer current
>>>ON ERROR &lcOldOnError

[ snip; I suggested: ]

Quote:>>IF Type("loWord") = "O"
>>  loWord.Visible=.T.
>>ENDIF

>(Sorry about delay - My ISP has only just started delivering news after
>a week's gap!!)

>This unfortunately will not work in all cases: it is quite possible for
>VFP to return TYPE("loWord") as O, but MSWord has shut down (or the link
>has been broken).

>Is there any way to test if the link is still *live* and only then set
>Visible to .T.?

Well you can always use your old approach, just do it _outside_ of ON ERROR
routine, e.g.,

oldonerr = ON("ERROR")
wordalive = .T.
ON ERROR wordalive = .F.
loWord.Visible = .T.
ON ERROR &oldonerr

and then in your main ON ERROR routine analyze the value of wordalive variable.

--
[ When replying, remove *'s from address ]
Alexandre Pechtchanski, Systems Manager, RUH, NY

 
 
 

Error trapping within my ON ERROR routine

Post by Ben Hambidg » Tue, 10 Apr 2001 20:09:34










>>>>I've got a single global error-handling routine. However, I'd like to
>>>>include a command in it that might generate an error. Elsewhere, the
>>>>following works:

>>>>lcOldOnError=ON("ERROR")
>>>>ON ERROR *  && Do nothing
>>>>loWord.Visible=.T.      && This will fail if loWord doesn't exist or
>>>>the link to MSWord is no longer current
>>>>ON ERROR &lcOldOnError
>[ snip; I suggested: ]
>>>IF Type("loWord") = "O"
>>>  loWord.Visible=.T.
>>>ENDIF

>>(Sorry about delay - My ISP has only just started delivering news after
>>a week's gap!!)

>>This unfortunately will not work in all cases: it is quite possible for
>>VFP to return TYPE("loWord") as O, but MSWord has shut down (or the link
>>has been broken).

>>Is there any way to test if the link is still *live* and only then set
>>Visible to .T.?

>Well you can always use your old approach, just do it _outside_ of ON ERROR
>routine, e.g.,

>oldonerr = ON("ERROR")
>wordalive = .T.
>ON ERROR wordalive = .F.
>loWord.Visible = .T.
>ON ERROR &oldonerr

>and then in your main ON ERROR routine analyze the value of wordalive variable.

This unfortunately does not directly solve my problem, because the whole
point is that I want it *inside* the error routine: i.e. if there is
ever an error, and a word document is still lurking invisibly behind the
scenes, then make it visible.

However, your suggestion gave me the 'third way': use a separate
'wordalive' variable that is set to to true whenever I start a new word
object, and release it whenever I make that word object visible. Then,
when I have an error, just test the 'wordalive' variable, and set
loWord.Visible if appropriate.

So thanks, your suggestion got me there in the end!

--
Ben Hambidge