This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Next revision Both sides next revision | ||
api:thread:zh [2023/10/20 13:12] hfsr [Thread Handle API] |
api:thread:zh [2023/10/20 13:15] hfsr [Thread Exception Example] |
||
---|---|---|---|
Line 299: | Line 299: | ||
调用`thread.waitForAll({t})`在功能上与调用`t:join()`一致。在进程结束时会对其子线程调用`thread.waitForAll`(若有)。子线程也通过同样的机制阻塞其父进程。 | 调用`thread.waitForAll({t})`在功能上与调用`t:join()`一致。在进程结束时会对其子线程调用`thread.waitForAll`(若有)。子线程也通过同样的机制阻塞其父进程。 | ||
- | ===== Thread Exception Example ===== | + | ===== 线程异常样例 ===== |
- | This example demonstrates what happens when a thread throws an exception. A thread stops executing and becomes "dead" when it throws an uncaught exception. The exception message is not printed to stdout nor stderr (see `t:resume()`) for details. | + | 此样例演示了线程抛出异常时会发生什么。线程在抛出未捕获的异常时会停止执行并进入“死亡”状态。报错信息将不会输出到stdout或stderr(详见`t:resume()`)。 |
```lua | ```lua | ||
Line 310: | Line 310: | ||
local reader = thread.create(function() | local reader = thread.create(function() | ||
print("reader start") | print("reader start") | ||
- | error("thread abort") -- throws an exception | + | error("thread abort") -- 抛出一个异常 |
print("reader done") | print("reader done") | ||
end) | end) | ||
Line 316: | Line 316: | ||
``` | ``` | ||
- | Output | + | 输出: |
``` | ``` | ||
p start | p start |