: <sql-index-exists> ( name -- error )
f swap sql-index-exists boa ;
-: ignore-error ( quot check: ( error -- ? ) -- )
- '[ dup @ [ drop ] [ rethrow ] if ] recover ; inline
-
: ignore-table-exists ( quot -- )
[ sql-table-exists? ] ignore-error ; inline
{ $values { "try" { $quotation ( ..a -- ..b ) } } { "recovery" { $quotation ( ..a error -- ..b ) } } }
{ $description "Calls the " { $snippet "try" } " quotation. If an exception is thrown in the dynamic extent of the " { $snippet "try" } " quotation, restores the data stack and calls the " { $snippet "recovery" } " quotation to handle the error." } ;
+HELP: ignore-error
+{ $values { "quot" quotation } { "check" quotation } }
+{ $description "Calls the quotation. If an exception is thrown which is matched by the 'check' quotation it is ignored. Otherwise the error is rethrown." } ;
+
+HELP: ignore-error/f
+{ $values { "quot" quotation } { "check" quotation } }
+{ $description "Like " { $link ignore-error } ", but if a matched exception is thrown " { $link f } " is put on the stack." } ;
+
HELP: ignore-errors
{ $values { "quot" quotation } }
-{ $description "Calls the quotation. If an exception is thrown in the dynamic extent of the quotation, restores the data stack and returns." } ;
+{ $description "Calls the quotation. If an exception is thrown in the dynamic extent of the quotation, restores the data stack and returns." }
+{ $notes "For safer alternatives to this word see " { $link ignore-error } " and " { $link ignore-error/f } "." } ;
HELP: in-callback?
{ $values { "?" boolean } }
-USING: accessors continuations debugger eval io kernel
-kernel.private math memory namespaces sequences tools.test
-vectors words ;
+USING: accessors continuations debugger eval io kernel kernel.private
+math math.ratios memory namespaces sequences tools.test vectors words
+;
IN: continuations.tests
: (callcc1-test) ( n obj -- n' obj )
"Hello" =
] unit-test
+{ 4 f } [
+ [ 20 5 / ] [ division-by-zero? ] ignore-error/f
+ [ 20 0 / ] [ division-by-zero? ] ignore-error/f
+] unit-test
+
"!!! The following error is part of the test" print
{ } [ [ 6 [ 12 [ "2 car" ] ] ] print-error ] unit-test
: ignore-errors ( quot -- )
[ drop ] recover ; inline
+: ignore-error ( quot check: ( error -- ? ) -- )
+ [ dup ] prepose [ [ drop ] [ rethrow ] if ] compose
+ recover ; inline
+
+: ignore-error/f ( quot check: ( error -- ? ) -- )
+ [ dup ] prepose [ [ drop f ] [ rethrow ] if ] compose
+ recover ; inline
+
: cleanup ( try cleanup-always cleanup-error -- )
[ compose [ dip rethrow ] curry recover ] [ drop ] 2bi call ; inline