[ CryptGenRandom win32-error=0/f ] keep
] with-destructors ;
-ERROR: no-windows-crypto-provider ;
+ERROR: no-windows-crypto-provider error ;
: try-crypto-providers ( seq -- windows-rng )
- [ first2 <windows-rng> ] try-find drop
- [ no-windows-crypto-provider ] unless* ;
+ [ first2 <windows-rng> ] attempt-all
+ dup windows-rng? [ no-windows-crypto-provider ] unless ;
[
{
recover\r
ignore-errors\r
}\r
-"Word for mapping over a sequence with a quotation until an element doesn't throw an exception:"\r
-{ $subsections\r
- try-find\r
-}\r
"Syntax sugar for defining errors:"\r
{ $subsections POSTPONE: ERROR: }\r
"Unhandled errors are reported in the listener and can be debugged using various tools. See " { $link "debugger" } "."\r
{ $values { "try" quotation } { "recovery" { $quotation "( error -- )" } } }\r
{ $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." } ;\r
\r
-HELP: try-find\r
-{ $values { "seq" sequence } { "try" quotation } { "result" "the first non-false, non-exception result of the quotation" } { "elt" "the first matching element, or " { $link f } } }\r
-{ $description "Applies the quotation to each element of the sequence, until the quotation outputs a true value, and attempts the next element if an exception is thrown. If the quotation ever yields a result which is not " { $link f } ", then the value is output, along with the element of the sequence which yielded this." } ;\r
-\r
HELP: ignore-errors\r
{ $values { "quot" quotation } }\r
{ $description "Calls the quotation. If an exception is thrown in the dynamic extent of the quotation, restores the data stack and returns." } ;\r
[ { 4 } ] [ { 2 2 } [ + ] with-datastack ] unit-test\r
\r
[ with-datastack ] must-infer\r
-\r
-[ { t 1 } ]\r
-[ { 1 1 } [ odd? ] try-find 2array ] unit-test\r
-\r
-[ { 9 3 } ]\r
-[ { 3 3 } [ sq ] try-find 2array ] unit-test\r
-\r
-[ { f f } ]\r
-[ { 1 1 } [ even? ] try-find 2array ] unit-test\r
-\r
-[ { f f } ]\r
-[ { 1 1 } [ "error" throw ] try-find 2array ] unit-test\r
: cleanup ( try cleanup-always cleanup-error -- )
[ compose [ dip rethrow ] curry recover ] [ drop ] 2bi call ; inline
-: try-find ( seq try -- result elt )
- [ curry [ drop f ] recover ] curry map-find ; inline
-
ERROR: attempt-all-error ;
: attempt-all ( seq quot -- obj )