aboutsummaryrefslogtreecommitdiff
path: root/doc/docs
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2025-05-28 22:15:35 +0800
committerLi Jin <dragon-fly@qq.com>2025-05-28 22:15:35 +0800
commit2f61682aea987cdc5dd1cf44097dbbc28a7cbd2b (patch)
tree13e1de7ce06df0d80c41f9213a18acbc8415eca9 /doc/docs
parent5604bbbb80bfcedb4a9085b90864e221f8104b33 (diff)
downloadyuescript-2f61682aea987cdc5dd1cf44097dbbc28a7cbd2b.tar.gz
yuescript-2f61682aea987cdc5dd1cf44097dbbc28a7cbd2b.tar.bz2
yuescript-2f61682aea987cdc5dd1cf44097dbbc28a7cbd2b.zip
Replace `try!` with `try?`.
Diffstat (limited to 'doc/docs')
-rwxr-xr-xdoc/docs/doc/README.md20
-rwxr-xr-xdoc/docs/zh/doc/README.md18
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
1524a, b, c = try! func! 1524a, b, c = try? func!
1525 1525
1526-- with nil coalescing operator 1526-- with nil coalescing operator
1527a = (try! func!) ?? "default" 1527a = (try? func!) ?? "default"
1528 1528
1529-- as function argument 1529-- as function argument
1530f try! func! 1530f try? func!
1531 1531
1532-- with catch block 1532-- with catch block
1533f try! 1533f try?
1534 print 123 1534 print 123
1535 func! 1535 func!
1536catch e 1536catch e
@@ -1539,16 +1539,16 @@ catch e
1539``` 1539```
1540<YueDisplay> 1540<YueDisplay>
1541<pre> 1541<pre>
1542a, b, c = try! func! 1542a, b, c = try? func!
1543 1543
1544-- with nil coalescing operator 1544-- with nil coalescing operator
1545a = (try! func!) ?? "default" 1545a = (try? func!) ?? "default"
1546 1546
1547-- as function argument 1547-- as function argument
1548f try! func! 1548f try? func!
1549 1549
1550-- with catch block 1550-- with catch block
1551f try! 1551f try?
1552 print 123 1552 print 123
1553 func! 1553 func!
1554catch e 1554catch 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
1522a, b, c = try! func! 1522a, b, c = try? func!
1523 1523
1524-- 与空值合并运算符一起使用 1524-- 与空值合并运算符一起使用
1525a = (try! func!) ?? "default" 1525a = (try? func!) ?? "default"
1526 1526
1527-- 作为函数参数 1527-- 作为函数参数
1528f try! func! 1528f try? func!
1529 1529
1530-- 带 catch 块的 try! 1530-- 带 catch 块的 try!
1531f try! 1531f try?
1532 print 123 1532 print 123
1533 func! 1533 func!
1534catch e 1534catch e
@@ -1537,16 +1537,16 @@ catch e
1537``` 1537```
1538<YueDisplay> 1538<YueDisplay>
1539<pre> 1539<pre>
1540a, b, c = try! func! 1540a, b, c = try? func!
1541 1541
1542-- 与空值合并运算符一起使用 1542-- 与空值合并运算符一起使用
1543a = (try! func!) ?? "default" 1543a = (try? func!) ?? "default"
1544 1544
1545-- 作为函数参数 1545-- 作为函数参数
1546f try! func! 1546f try? func!
1547 1547
1548-- 带 catch 块的 try! 1548-- 带 catch 块的 try!
1549f try! 1549f try?
1550 print 123 1550 print 123
1551 func! 1551 func!
1552catch e 1552catch e