diff options
Diffstat (limited to 'doc/docs')
| -rwxr-xr-x | doc/docs/doc/README.md | 20 | ||||
| -rwxr-xr-x | doc/docs/zh/doc/README.md | 18 |
2 files changed, 19 insertions, 19 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index 1d9c8ad..c0312f7 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md | |||
| @@ -1516,21 +1516,21 @@ catch err | |||
| 1516 | </pre> | 1516 | </pre> |
| 1517 | </YueDisplay> | 1517 | </YueDisplay> |
| 1518 | 1518 | ||
| 1519 | ### Try! | 1519 | ### Try? |
| 1520 | 1520 | ||
| 1521 | `try!` is a more concise error handling syntax that omit the boolean status from the `try` statement, and it will return the result from the try block when success, otherwise return nil instead of error object. | 1521 | `try?` is a simplified use for error handling syntax that omit the boolean status from the `try` statement, and it will return the result from the try block when success, return nil instead of error object otherwise. |
| 1522 | 1522 | ||
| 1523 | ```moonscript | 1523 | ```moonscript |
| 1524 | a, b, c = try! func! | 1524 | a, b, c = try? func! |
| 1525 | 1525 | ||
| 1526 | -- with nil coalescing operator | 1526 | -- with nil coalescing operator |
| 1527 | a = (try! func!) ?? "default" | 1527 | a = (try? func!) ?? "default" |
| 1528 | 1528 | ||
| 1529 | -- as function argument | 1529 | -- as function argument |
| 1530 | f try! func! | 1530 | f try? func! |
| 1531 | 1531 | ||
| 1532 | -- with catch block | 1532 | -- with catch block |
| 1533 | f try! | 1533 | f try? |
| 1534 | print 123 | 1534 | print 123 |
| 1535 | func! | 1535 | func! |
| 1536 | catch e | 1536 | catch e |
| @@ -1539,16 +1539,16 @@ catch e | |||
| 1539 | ``` | 1539 | ``` |
| 1540 | <YueDisplay> | 1540 | <YueDisplay> |
| 1541 | <pre> | 1541 | <pre> |
| 1542 | a, b, c = try! func! | 1542 | a, b, c = try? func! |
| 1543 | 1543 | ||
| 1544 | -- with nil coalescing operator | 1544 | -- with nil coalescing operator |
| 1545 | a = (try! func!) ?? "default" | 1545 | a = (try? func!) ?? "default" |
| 1546 | 1546 | ||
| 1547 | -- as function argument | 1547 | -- as function argument |
| 1548 | f try! func! | 1548 | f try? func! |
| 1549 | 1549 | ||
| 1550 | -- with catch block | 1550 | -- with catch block |
| 1551 | f try! | 1551 | f try? |
| 1552 | print 123 | 1552 | print 123 |
| 1553 | func! | 1553 | func! |
| 1554 | catch e | 1554 | catch e |
diff --git a/doc/docs/zh/doc/README.md b/doc/docs/zh/doc/README.md index 0fa1fed..b4e594c 100755 --- a/doc/docs/zh/doc/README.md +++ b/doc/docs/zh/doc/README.md | |||
| @@ -1516,19 +1516,19 @@ catch err | |||
| 1516 | 1516 | ||
| 1517 | ### 错误处理简化 | 1517 | ### 错误处理简化 |
| 1518 | 1518 | ||
| 1519 | `try!` 是 `try` 的简化语法,它不再返回 `try` 语句的布尔状态,并在成功时直接返回 `try` 代码块的结果,失败时返回 `nil` 值而非错误对象。 | 1519 | `try?` 是 `try` 的功能简化语法,它不再返回 `try` 语句的布尔状态,并在成功时直接返回 `try` 代码块的结果,失败时返回 `nil` 值而非错误对象。 |
| 1520 | 1520 | ||
| 1521 | ```moonscript | 1521 | ```moonscript |
| 1522 | a, b, c = try! func! | 1522 | a, b, c = try? func! |
| 1523 | 1523 | ||
| 1524 | -- 与空值合并运算符一起使用 | 1524 | -- 与空值合并运算符一起使用 |
| 1525 | a = (try! func!) ?? "default" | 1525 | a = (try? func!) ?? "default" |
| 1526 | 1526 | ||
| 1527 | -- 作为函数参数 | 1527 | -- 作为函数参数 |
| 1528 | f try! func! | 1528 | f try? func! |
| 1529 | 1529 | ||
| 1530 | -- 带 catch 块的 try! | 1530 | -- 带 catch 块的 try! |
| 1531 | f try! | 1531 | f try? |
| 1532 | print 123 | 1532 | print 123 |
| 1533 | func! | 1533 | func! |
| 1534 | catch e | 1534 | catch e |
| @@ -1537,16 +1537,16 @@ catch e | |||
| 1537 | ``` | 1537 | ``` |
| 1538 | <YueDisplay> | 1538 | <YueDisplay> |
| 1539 | <pre> | 1539 | <pre> |
| 1540 | a, b, c = try! func! | 1540 | a, b, c = try? func! |
| 1541 | 1541 | ||
| 1542 | -- 与空值合并运算符一起使用 | 1542 | -- 与空值合并运算符一起使用 |
| 1543 | a = (try! func!) ?? "default" | 1543 | a = (try? func!) ?? "default" |
| 1544 | 1544 | ||
| 1545 | -- 作为函数参数 | 1545 | -- 作为函数参数 |
| 1546 | f try! func! | 1546 | f try? func! |
| 1547 | 1547 | ||
| 1548 | -- 带 catch 块的 try! | 1548 | -- 带 catch 块的 try! |
| 1549 | f try! | 1549 | f try? |
| 1550 | print 123 | 1550 | print 123 |
| 1551 | func! | 1551 | func! |
| 1552 | catch e | 1552 | catch e |
