embedded systems developers tools, cross compilers
  Home  |   SwiftX Archive  |   SwiftForth Archive  |

THROW Q, CATCH Corruption

From: Bulgrien, Dennis <Dennis.Bulgrien_at_TripointGlobal.com>
Date: Tue, 5 Feb 2002 14:20:41 -0600

I copied the following sample code from Handbook.pdf, 2.6 EXCEPTION
HANDLING, into debug.f. I added a .S to COULD-FAIL and two of DEPTH .
around CATCH for diagnostics. There are times when I get the intended
results (pressing Q yields "There was an exception") and there are times
when the stack is corrupted (pressing Q yeilds "The character was Q"). When
in a corrupting state (seen by .S output) executing ABORT seemed to correct
it. Has anyone else seen such odd behavior?

Original
--------
: COULD-FAIL ( -- c) KEY DUP [CHAR] Q = IF
   1 THROW THEN ;
: DO-IT ( n n -- c) 2DROP COULD-FAIL ;
: TRY-IT ( -- ) 1 2 ['] DO-IT CATCH IF
   2DROP ." There was an exception" CR
   ELSE ." The character was " EMIT CR THEN ;

Diagnostic
----------
: COULD-FAIL ( -- c) KEY DUP [CHAR] Q .S = IF
   1 THROW THEN ;
: DO-IT ( n n -- c) 2DROP COULD-FAIL ;
: TRY-IT ( -- ) 1 2 ['] DO-IT DEPTH . CATCH DEPTH . IF
   2DROP ." There was an exception" CR
   ELSE ." The character was " EMIT CR THEN ;

Diagnostic Output
-----------------
INCLUDE DEBUG
TARGET READY
SwiftX/68K FORCE CPU-30/33
 ok
TRY-IT 3
7777 7777 81 <-Top 2 The character was a
 ok
TRY-IT 3
113 113 81 <-Top 2 The character was q
 ok
TRY-IT 3
81 81 81 <-Top 3 There was an exception
 ok
INCLUDE DEBUG
TARGET READY
SwiftX/68K FORCE CPU-30/33
 ok
TRY-IT 3
7761 7761 81 <-Top 2 The character was Q
 ok
TRY-IT 3
209777 209777 81 <-Top 2 The character was q
 ok
TRY-IT 3
7693 7693 81 <-Top 2 The character was

 ok
TRY-IT 3
8273 8273 81 <-Top 2 The character was Q
 ok
ABORT
Target throw code: -1

TRY-IT 3
113 113 81 <-Top 2 The character was q
 ok
TRY-IT 3
81 81 81 <-Top 3 There was an exception
 ok
----------------------------------------------------------------------
swiftx_at_forth.com The SwiftX programming discussion email list
To unsubscribe, send subject "unsubscribe swiftx" 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/swiftx -- check them out!
----------------------------------------------------------------------
THIS LIST IS NOT FOR BUG REPORTS! Send bug reports to support_at_forth.com.
Received on Tue Feb 05 2002 - 12:22:36 PST

This archive was generated by hypermail 2.2.0 : Wed Jan 07 2009 - 03:04:23 PST