From 2f61682aea987cdc5dd1cf44097dbbc28a7cbd2b Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 28 May 2025 22:15:35 +0800 Subject: Replace `try!` with `try?`. --- doc/docs/doc/README.md | 20 ++++++++++---------- doc/docs/zh/doc/README.md | 18 +++++++++--------- 2 files changed, 19 insertions(+), 19 deletions(-) (limited to 'doc') 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 -### Try! +### Try? -`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. +`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. ```moonscript -a, b, c = try! func! +a, b, c = try? func! -- with nil coalescing operator -a = (try! func!) ?? "default" +a = (try? func!) ?? "default" -- as function argument -f try! func! +f try? func! -- with catch block -f try! +f try? print 123 func! catch e @@ -1539,16 +1539,16 @@ catch e ```
-a, b, c = try! func!
+a, b, c = try? func!
 
 -- with nil coalescing operator
-a = (try! func!) ?? "default"
+a = (try? func!) ?? "default"
 
 -- as function argument
-f try! func!
+f try? func!
 
 -- with catch block
-f try!
+f try?
   print 123
   func!
 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
 
 ### 错误处理简化
 
-`try!` 是 `try` 的简化语法,它不再返回 `try` 语句的布尔状态,并在成功时直接返回 `try` 代码块的结果,失败时返回 `nil` 值而非错误对象。
+`try?` 是 `try` 的功能简化语法,它不再返回 `try` 语句的布尔状态,并在成功时直接返回 `try` 代码块的结果,失败时返回 `nil` 值而非错误对象。
 
 ```moonscript
-a, b, c = try! func!
+a, b, c = try? func!
 
 -- 与空值合并运算符一起使用
-a = (try! func!) ?? "default"
+a = (try? func!) ?? "default"
 
 -- 作为函数参数
-f try! func!
+f try? func!
 
 -- 带 catch 块的 try!
-f try!
+f try?
   print 123
   func!
 catch e
@@ -1537,16 +1537,16 @@ catch e
 ```
 
 
-a, b, c = try! func!
+a, b, c = try? func!
 
 -- 与空值合并运算符一起使用
-a = (try! func!) ?? "default"
+a = (try? func!) ?? "default"
 
 -- 作为函数参数
-f try! func!
+f try? func!
 
 -- 带 catch 块的 try!
-f try!
+f try?
   print 123
   func!
 catch e
-- 
cgit v1.2.3-55-g6feb