factor/library/errors.factor

25 lines
747 B
Factor
Raw Normal View History

! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
2005-03-21 14:39:46 -05:00
IN: errors
2006-05-15 01:01:47 -04:00
USING: kernel kernel-internals sequences ;
: >c ( continuation -- ) catchstack* push ;
: c> ( -- continuation ) catchstack* pop ;
2004-07-17 18:35:09 -04:00
2006-01-07 16:03:31 -05:00
: catch ( try -- error | try: -- )
2005-09-18 23:22:58 -04:00
[ >c call f c> drop f ] callcc1 nip ; inline
2005-09-14 00:37:50 -04:00
: rethrow ( error -- )
catchstack* empty? [ die ] [ c> continue-with ] if ;
: cleanup ( try cleanup -- | try: -- | cleanup: -- )
[ >c >r call c> drop r> call ]
2006-01-07 16:03:31 -05:00
[ drop (continue-with) >r nip call r> rethrow ] ifcc ;
inline
2005-09-21 01:12:16 -04:00
2005-09-22 16:21:36 -04:00
: recover ( try recovery -- | try: -- | recovery: error -- )
[ >c drop call c> drop ]
2005-09-22 23:18:12 -04:00
[ drop (continue-with) rot drop swap call ] ifcc ; inline
2005-03-25 21:43:06 -05:00
GENERIC: error. ( error -- )