Hi Paul,

Here's a very simple little illustration prg I wrote for a colleague who 
I'm trying to encourage TRY..CATCH usage with. Of course, you'll have to 
have a table called sales with a column called saleno that is not 
numeric to be able to see all 3 exception scenarios here. Otherwise, 
you'll just hit the last CATCH.

There were some good illustrations from the VFP POV in chapter 12 of  
the Hentzenwerke What's New in VFP 8 book.

ACTIVATE SCREEN
CLEAR
TEXT
To see how try..catch works
RUN this little program as is
Then comment the first line in the TRY block and uncomment the second line
FINALLY comment the first two lines, leaving only the last line
ENDTEXT
IF MESSAGEBOX([Ready to go?],0+4+32,[TRY..CATCH Example 1])=6
    TRY
        m.c=[SELECT fred FROM sales INTO CURSOR xxx]
*!*            m.c=[SELECT * FROM sales WHERE saleno=1 INTO CURSOR xxx]
        &c
    CATCH TO m.loError WHEN m.loError.ErrorNo=1806
        MESSAGEBOX([Column is missing])
    CATCH TO m.loError WHEN m.loError.ErrorNo=107
        MESSAGEBOX([Operator/operand type mismatch])
    CATCH
        MESSAGEBOX([Some other problem])
    FINALLY
*!* cleanup code goes here
    ENDTRY
ENDIF

Paul Newton wrote:
> Paul
>
> Many thanks for your reply.  I still do not seem to be able to get my 
> head around the TRY syntax but I will give it a try anyway ! Are you 
> suggesting that the CATCH clause doesn't actually have to contain 
> anything ?  In this case I don't need to trap an error and in the past 
> might have saved ON("ERROR"), issued an ON ERROR * and restored the ON 
> ERROR.
>
> The examples I have seen for TRY... all seem a bit contrived rather than 
> demonstrating "real-life" scenarios - also I need to get my head around 
> how it works with and without an (ON ERROR type) handler in place.  If 
> anybody has any "reading suggestions" I will gladly do some homework
>
> Tx again
>
> Paul Newton
>   

-- 
Richard Kaye
Vice President
Artfact/RFC Systems
Voice: 617.219.1038
Fax:  617.219.1001

For the fastest response time, please send your support
queries to:

Technical Support - [EMAIL PROTECTED]
Australian Support - [EMAIL PROTECTED]
Internet Support - [EMAIL PROTECTED]
All Other Requests - [EMAIL PROTECTED]

---------------------------------------------------------
This message has been checked for viruses before sending.
---------------------------------------------------------



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** 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.

Reply via email to