File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed
en/guide/interview/golang/basic
guide/interview/golang/basic Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ export default hopeTheme({
15
15
16
16
logo : "/logo.svg" ,
17
17
18
- repo : "github.com/ suyuan32/GoGuide" ,
18
+ repo : "suyuan32/GoGuide" ,
19
19
20
20
docsDir : "src" ,
21
21
Original file line number Diff line number Diff line change 28
28
29
29
:::
30
30
31
+ ## Map
31
32
32
33
### Is the traversal of a Map using range ordered or unordered?
33
34
@@ -68,4 +69,16 @@ If the value of the map is
68
69
69
70
::: tip Exclusive for members
70
71
[ Code combat analysis] ( https://articles.zsxq.com/id_4w1a11i6xrw0.html )
72
+ :::
73
+
74
+ ### Can a panic caused by a map be recovered?
75
+
76
+ ::: details Answer
77
+ 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.
78
+
79
+ ``` go
80
+ if h.flags &hashWriting != 0 {
81
+ throw (" concurrent map read and map write" )
82
+ }
83
+ ```
71
84
:::
Original file line number Diff line number Diff line change 29
29
30
30
:::
31
31
32
+ ## Map 相关
33
+
32
34
### Map 使用 range 遍历时是有序还是无序的?
33
35
34
36
::: details 答案
@@ -69,3 +71,15 @@ Map 在内部使用哈希算法放置元素,在自动扩容时又会重新计
69
71
::: tip 会员专属
70
72
[ 代码实战解析] ( https://articles.zsxq.com/id_4w1a11i6xrw0.html )
71
73
:::
74
+
75
+ ### Map 产生的 panic 异常能被 recover 吗?
76
+
77
+ ::: details 答案
78
+ Map 由于并发读写导致的 panic 是不能被 recover 的,因为 Map 的异常使用 ` runtime.throw() ` 抛出,这类异常不能被 recover。
79
+
80
+ ``` go
81
+ if h.flags &hashWriting != 0 {
82
+ throw (" concurrent map read and map write" )
83
+ }
84
+ ```
85
+ :::
You can’t perform that action at this time.
0 commit comments