From 21f061239a3ac9c4b0ab90cc855a06c824c2f1fd Mon Sep 17 00:00:00 2001 From: Ryan Su Date: Wed, 22 May 2024 08:56:38 +0800 Subject: [PATCH] docs: update docs --- src/.vuepress/theme.ts | 2 +- src/en/guide/interview/golang/basic/2-medium.md | 13 +++++++++++++ src/guide/interview/golang/basic/2-medium.md | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/.vuepress/theme.ts b/src/.vuepress/theme.ts index 5008b98c..03732a93 100644 --- a/src/.vuepress/theme.ts +++ b/src/.vuepress/theme.ts @@ -15,7 +15,7 @@ export default hopeTheme({ logo: "/logo.svg", - repo: "github.com/suyuan32/GoGuide", + repo: "suyuan32/GoGuide", docsDir: "src", diff --git a/src/en/guide/interview/golang/basic/2-medium.md b/src/en/guide/interview/golang/basic/2-medium.md index cdcf2f28..01b1175b 100644 --- a/src/en/guide/interview/golang/basic/2-medium.md +++ b/src/en/guide/interview/golang/basic/2-medium.md @@ -28,6 +28,7 @@ head: ::: +## Map ### Is the traversal of a Map using range ordered or unordered? @@ -68,4 +69,16 @@ If the value of the map is ::: tip Exclusive for members [Code combat analysis](https://articles.zsxq.com/id_4w1a11i6xrw0.html) +::: + +### Can a panic caused by a map be recovered? + +::: details Answer +A panic caused by concurrent read and write operations on a map cannot be recovered. This is because map-related panics are thrown using `runtime.throw()`, which cannot be recovered. + +```go +if h.flags&hashWriting != 0 { + throw("concurrent map read and map write") +} +``` ::: \ No newline at end of file diff --git a/src/guide/interview/golang/basic/2-medium.md b/src/guide/interview/golang/basic/2-medium.md index 4711ef74..bb8f0c43 100644 --- a/src/guide/interview/golang/basic/2-medium.md +++ b/src/guide/interview/golang/basic/2-medium.md @@ -29,6 +29,8 @@ head: ::: +## Map 相关 + ### Map 使用 range 遍历时是有序还是无序的? ::: details 答案 @@ -69,3 +71,15 @@ Map 在内部使用哈希算法放置元素,在自动扩容时又会重新计 ::: tip 会员专属 [代码实战解析](https://articles.zsxq.com/id_4w1a11i6xrw0.html) ::: + +### Map 产生的 panic 异常能被 recover 吗? + +::: details 答案 +Map 由于并发读写导致的 panic 是不能被 recover 的,因为 Map 的异常使用 `runtime.throw()` 抛出,这类异常不能被 recover。 + +```go +if h.flags&hashWriting != 0 { + throw("concurrent map read and map write") +} +``` +::: \ No newline at end of file