diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-06-05 13:16:25 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-06-05 13:16:25 -0300 |
commit | b4d5dff8ec4f1c8a44db66d368e95d359b04aea7 (patch) | |
tree | e87fbd3bcbf8a271429ee31f32eaf928058ab376 /manual | |
parent | 14edd364c3abcb758e74c68a2bdd4ddaeefdae2a (diff) | |
download | lua-b4d5dff8ec4f1c8a44db66d368e95d359b04aea7.tar.gz lua-b4d5dff8ec4f1c8a44db66d368e95d359b04aea7.tar.bz2 lua-b4d5dff8ec4f1c8a44db66d368e95d359b04aea7.zip |
Multiple errors in '__toclose' report the first one
When there are multiple errors when closing objects, the error
reported by the protected call is the first one, for two reasons:
First, other errors may be caused by this one;
second, the first error is handled in the original execution context,
and therefore has the full traceback.
Diffstat (limited to 'manual')
-rw-r--r-- | manual/manual.of | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/manual/manual.of b/manual/manual.of index 4c9c20b2..2c0957b9 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -1541,11 +1541,17 @@ if there was no error, the second argument is @nil. | |||
1541 | 1541 | ||
1542 | If several to-be-closed variables go out of scope at the same event, | 1542 | If several to-be-closed variables go out of scope at the same event, |
1543 | they are closed in the reverse order that they were declared. | 1543 | they are closed in the reverse order that they were declared. |
1544 | |||
1544 | If there is any error while running a closing method, | 1545 | If there is any error while running a closing method, |
1545 | that error is handled like an error in the regular code | 1546 | that error is handled like an error in the regular code |
1546 | where the variable was defined; | 1547 | where the variable was defined; |
1547 | in particular, | 1548 | in particular, |
1548 | the other pending closing methods will still be called. | 1549 | the other pending closing methods will still be called. |
1550 | After an error, | ||
1551 | other errors in closing methods | ||
1552 | interrupt the respective method, | ||
1553 | but are otherwise ignored; | ||
1554 | the error reported is the original one. | ||
1549 | 1555 | ||
1550 | If a coroutine yields inside a block and is never resumed again, | 1556 | If a coroutine yields inside a block and is never resumed again, |
1551 | the variables visible at that block will never go out of scope, | 1557 | the variables visible at that block will never go out of scope, |
@@ -1553,11 +1559,12 @@ and therefore they will never be closed. | |||
1553 | Similarly, if a coroutine ends with an error, | 1559 | Similarly, if a coroutine ends with an error, |
1554 | it does not unwind its stack, | 1560 | it does not unwind its stack, |
1555 | so it does not close any variable. | 1561 | so it does not close any variable. |
1556 | You should either use finalizers | 1562 | In both cases, |
1557 | or call @Lid{coroutine.close} to close the variables in these cases. | 1563 | you should either use finalizers |
1558 | However, note that if the coroutine was created | 1564 | or call @Lid{coroutine.close} to close the variables. |
1565 | However, if the coroutine was created | ||
1559 | through @Lid{coroutine.wrap}, | 1566 | through @Lid{coroutine.wrap}, |
1560 | then its corresponding function will close all variables | 1567 | then its corresponding function will close the coroutine |
1561 | in case of errors. | 1568 | in case of errors. |
1562 | 1569 | ||
1563 | } | 1570 | } |
@@ -3932,7 +3939,7 @@ Returns a status code: | |||
3932 | @Lid{LUA_OK} for no errors in closing methods, | 3939 | @Lid{LUA_OK} for no errors in closing methods, |
3933 | or an error status otherwise. | 3940 | or an error status otherwise. |
3934 | In case of error, | 3941 | In case of error, |
3935 | leave the error object on the stack, | 3942 | leaves the error object on the top of the stack, |
3936 | 3943 | ||
3937 | } | 3944 | } |
3938 | 3945 | ||
@@ -6355,6 +6362,7 @@ Closes coroutine @id{co}, | |||
6355 | that is, | 6362 | that is, |
6356 | closes all its pending to-be-closed variables | 6363 | closes all its pending to-be-closed variables |
6357 | and puts the coroutine in a dead state. | 6364 | and puts the coroutine in a dead state. |
6365 | The given coroutine must be dead or suspended. | ||
6358 | In case of error closing some variable, | 6366 | In case of error closing some variable, |
6359 | returns @false plus the error object; | 6367 | returns @false plus the error object; |
6360 | otherwise returns @true. | 6368 | otherwise returns @true. |
@@ -6412,7 +6420,8 @@ true when the running coroutine is the main one. | |||
6412 | 6420 | ||
6413 | Returns the status of the coroutine @id{co}, as a string: | 6421 | Returns the status of the coroutine @id{co}, as a string: |
6414 | @T{"running"}, | 6422 | @T{"running"}, |
6415 | if the coroutine is running (that is, it called @id{status}); | 6423 | if the coroutine is running |
6424 | (that is, it is the one that called @id{status}); | ||
6416 | @T{"suspended"}, if the coroutine is suspended in a call to @id{yield}, | 6425 | @T{"suspended"}, if the coroutine is suspended in a call to @id{yield}, |
6417 | or if it has not started running yet; | 6426 | or if it has not started running yet; |
6418 | @T{"normal"} if the coroutine is active but not running | 6427 | @T{"normal"} if the coroutine is active but not running |