factor/library/errors.factor

30 lines
868 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
USING: kernel kernel-internals lists sequences ;
2005-08-25 15:27:38 -04:00
TUPLE: no-method object generic ;
2005-09-17 22:25:18 -04:00
: no-method ( object generic -- ) <no-method> throw ;
2004-11-25 21:51:47 -05:00
: >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
: 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
2006-01-07 16:03:31 -05:00
: rethrow ( error -- )
catchstack* empty?
[ die "Can't happen" throw ] [ c> continue-with ] if ;
2005-03-25 21:43:06 -05:00
GENERIC: error. ( error -- )