programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re: CATCH

From: Rick VanNorman <rick_at_neverslow.com>
Date: Wed, 04 Apr 2001 10:55:48 -0700

Mike,

I'm not sure what you really intend here, but in principle it
should work just fine. The rule is that the catch handler must
be able to deal with errors. It *may* deal with any errors it
detects by simply THROW-ing to whom-ever called it via CATCH
but this is not required.

For instance,

VARIABLE POO

: TEST ( -- )
   1 POO +! POO @ 4 > THROW ;

: TRY ( -- )
   ['] TEST CATCH IF ." Poo was greater than 4" THEN ;

is perfectly valid. Nothing TEST does deserves a higher-level
catch. Do note that you must clean up your stack when an error
is detected, and that the content of what you clean up is
indeterminate.

For instance,

VARIABLE POO

: TEST ( a b -- )
   + POO ! POO @ 100 > THROW ;

: TRY ( a b -- )
   ['] TEST CATCH IF DROP DROP DROP
      ." Poo is greater than 100"
   THEN ;

The three items dropped if catch returns true are not predictable.
If catch returns zero, the stack effect is exactly what the word
caught would be.

Hope this helps.

Rick

*********** REPLY SEPARATOR ***********

On 4/4/2001 at 10:35 AM Mike Ghan wrote:

>Hello all, does each CATCH require a matching THROW or is it possible
>to use CATCH alone and simply drop it's result. For example:
>
>['] FOO CATCH ( throw_code ) \ FOO creates structures
> \ which must be destroyed.
>['] CLEANUP CATCH DROP \ Need to return here
> \ regardless of error.
>DESTROY-FOO \ Destroy FOO's structures.
>( throw-code ) THROW \ Act on first CATCH
> \ throw code.
>

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Received on Wed Apr 04 2001 - 10:55:45 PDT

This archive was generated by hypermail 2.2.0 : Thu Nov 20 2008 - 03:04:18 PST