kopia lustrzana https://github.com/backface/turtlestitch
updated try-catch library
rodzic
4d81f4de06
commit
71a08a82b0
|
@ -10,6 +10,7 @@
|
|||
### 2021-06-15
|
||||
* threads: added exception handling primitives for try/catch
|
||||
* extensions: added try-catch extension primitives
|
||||
* updated try-catch library
|
||||
|
||||
### 2021-06-15
|
||||
* extensions: tweaked world-map primitives
|
||||
|
|
|
@ -1 +1 @@
|
|||
<blocks app="Snap! 6, https://snap.berkeley.edu" version="1"><block-definition s="safely try %'action' then if %'error' %'handler'" type="command" category="control"><comment w="276" collapsed="false">Catch errors.

Runs the first script. If it succeeds, nothing else happens.
But if it has an error (something that would otherwise result
in a red halo around the block), then the second script is run,
with the text of the error message that would have been shown in the variable ERROR.</comment><header></header><code></code><translations>pt:tenta executar _ e, em caso de erro _ , executa _
</translations><inputs><input type="%cs"></input><input type="%upvar"></input><input type="%cs"></input></inputs><script><custom-block s="let %upvar be %s"><l>reset</l><block s="evaluate"><block s="reportJSFunction"><list><l>proc</l></list><l>var oldHandleError = proc.handleError,
 oldCatchingErrors = proc.isCatchingErrors;

return function(){
 proc.handleError = oldHandleError;
 proc.isCatchingErrors = oldCatchingErrors;
}</l></block><list></list></block></custom-block><block s="doCallCC"><block s="reifyScript"><script><block s="doRun"><block s="reportJSFunction"><list><l>reset</l><l>action</l><l>handler</l><l>proc</l></list><l>proc.isCatchingErrors = true;
proc.handleError = function(error, element){
 reset();
 proc.context = handler;
 proc.context.variables.setVar("error", error);
}

try{
 proc.evaluate(action, new List(), true);
}
catch(e){
 proc.handleError(e, null);
} </l></block><list><block var="reset"/><block var="action"/><block s="reifyScript"><script><block s="doRun"><block s="reifyScript"><script><block s="doRun"><block var="handler"/><list></list></block><block s="doRun"><block var="return"/><list></list></block></script><list></list></block><list></list></block></script><list></list></block></list></block></script><list><l>return</l></list></block></block><block s="doRun"><block var="reset"/><list></list></block></script></block-definition><block-definition s="error %'msg'" type="command" category="control"><comment w="268.6666666666667" collapsed="false">Throw an error.

Makes a red halo appear around the script that runs it,
with the input text shown in a speech balloon next to
the script, just like any Snap! error.

This is useful to put in the second script of SAFELY TRY
after some other instructions to undo the partial work of
the first script.</comment><header></header><code></code><translations>pt:lança o erro _
</translations><inputs><input type="%txt"></input></inputs><script><block s="doRun"><block s="reportJSFunction"><list><l>msg</l></list><l>throw new Error(msg);</l></block><list><block var="msg"/></list></block></script></block-definition><block-definition s="let %'var' be %'val'" type="command" category="other"><comment w="183.33333333333334" collapsed="false">LET (FOO) BE (5)
is equivalent to
SCRIPT VARIABLES (FOO)
SET (FOO) TO (5)</comment><header></header><code></code><translations>pt:cria a variável de guião _ com valor _
</translations><inputs><input type="%upvar"></input><input type="%s"></input></inputs><script><block s="doSetVar"><l>var</l><block var="val"/></block></script></block-definition><block-definition s="safely try reporting %'this' then if %'error' report %'that'" type="reporter" category="control"><comment w="316.6666666666667" collapsed="false">Catch errors in a reporter.

Evaluates its first input. If that expression successfully reports a value, this block reports that value. If the expression causes a Snap! error,
then the final input slot is evaluated with the text of what would have
been the error message in variable ERROR. SAFELY TRY then reports the value of that final expression.

Sometimes you'll want to throw an error in the final expression. You
can put an ERROR block inside a CALL block to do that.</comment><header></header><code></code><translations></translations><inputs><input type="%anyUE"></input><input type="%upvar"></input><input type="%anyUE"></input></inputs><script><block s="doDeclareVariables"><list><l>value</l></list></block><custom-block s="safely try %cs then if %upvar %cs"><script><block s="doSetVar"><l>value</l><block s="evaluate"><block var="this"/><list></list></block></block></script><l>err</l><script><block s="doSetVar"><l>error</l><block var="err"/></block><block s="doSetVar"><l>value</l><block s="evaluate"><block var="that"/><list></list></block></block></script></custom-block><block s="doReport"><block var="value"/></block></script></block-definition></blocks>
|
||||
<blocks app="Snap! 6, https://snap.berkeley.edu" version="1"><block-definition s="safely try %'action' then if %'error' %'handler'" type="command" category="control"><comment w="276" collapsed="false">Catch errors.

Runs the first script. If it succeeds, nothing else happens.
But if it has an error (something that would otherwise result
in a red halo around the block), then the second script is run,
with the text of the error message that would have been shown in the variable ERROR.</comment><header></header><code></code><translations>pt:tenta executar _ e, em caso de erro _ , executa _
</translations><inputs><input type="%cs"></input><input type="%upvar"></input><input type="%cs"></input></inputs><script><block s="doApplyExtension"><l>err_try(cmd, catch, err)</l><list><block var="action"/><block var="handler"/><l>error</l></list></block><block s="doApplyExtension"><l>err_reset</l><list></list></block></script></block-definition><block-definition s="error %'msg'" type="command" category="control"><comment w="268.6666666666667" collapsed="false">Throw an error.

Makes a red halo appear around the script that runs it,
with the input text shown in a speech balloon next to
the script, just like any Snap! error.

This is useful to put in the second script of SAFELY TRY
after some other instructions to undo the partial work of
the first script.</comment><header></header><code></code><translations>pt:lança o erro _
</translations><inputs><input type="%txt"></input></inputs><script><block s="doApplyExtension"><l>err_error(msg)</l><list><block var="msg"/></list></block></script></block-definition><block-definition s="safely try reporting %'this' then if %'error' report %'that'" type="reporter" category="control"><comment w="316.6666666666667" collapsed="false">Catch errors in a reporter.

Evaluates its first input. If that expression successfully reports a value, this block reports that value. If the expression causes a Snap! error,
then the final input slot is evaluated with the text of what would have
been the error message in variable ERROR. SAFELY TRY then reports the value of that final expression.

Sometimes you'll want to throw an error in the final expression. You
can put an ERROR block inside a CALL block to do that.</comment><header></header><code></code><translations></translations><inputs><input type="%anyUE"></input><input type="%upvar"></input><input type="%anyUE"></input></inputs><script><block s="doDeclareVariables"><list><l>value</l></list></block><custom-block s="safely try %cs then if %upvar %cs"><script><block s="doSetVar"><l>value</l><block s="evaluate"><block var="this"/><list></list></block></block></script><l>err</l><script><block s="doSetVar"><l>error</l><block var="err"/></block><block s="doSetVar"><l>value</l><block s="evaluate"><block var="that"/><list></list></block></block></script></custom-block><block s="doReport"><block var="value"/></block></script></block-definition></blocks>
|
Ładowanie…
Reference in New Issue