go20/day03/error/mpg.drawio
yumaojun03 bb8564ba49 ```
feat(error): 添加Go语言异常处理完整教程

详细介绍了Go语言中的错误处理机制,包括:

- error类型的处理方式,通过返回值处理异常
- panic和recover的使用方法,以及如何从程序崩溃中恢复
- defer函数的应用,用于资源清理和崩溃恢复
- 错误创建的不同方式:errors.New、fmt.Errorf、errors.Join
- 错误比较的最佳实践:使用errors.Is进行错误判断
- 实际代码示例展示了目录遍历中的错误处理
- 添加了协程调度的架构图解
```
2026-01-25 16:38:17 +08:00

87 lines
6.5 KiB
Plaintext

<mxfile host="65bd71144e">
<diagram id="sOwmlNTTQTTo7f71Gu_9" name="第 1 页">
<mxGraphModel dx="1134" dy="585" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="2" value="CPU(物理核心, 超线程&amp;lt;逻辑处理核心&amp;gt;)" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="140" y="180" width="620" height="290" as="geometry"/>
</mxCell>
<mxCell id="3" value="处理核心" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="190" y="350" width="130" height="80" as="geometry"/>
</mxCell>
<mxCell id="4" value="&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;处理核心&lt;/span&gt;" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="580" y="350" width="130" height="80" as="geometry"/>
</mxCell>
<mxCell id="6" value="OS 进程" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="190" y="210" width="540" height="90" as="geometry"/>
</mxCell>
<mxCell id="7" value="线程" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="214" y="235" width="100" height="40" as="geometry"/>
</mxCell>
<mxCell id="8" value="线程" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="510" y="235" width="100" height="40" as="geometry"/>
</mxCell>
<mxCell id="9" value="线程" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="610" y="235" width="100" height="40" as="geometry"/>
</mxCell>
<mxCell id="10" value="线程" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="314" y="235" width="100" height="40" as="geometry"/>
</mxCell>
<mxCell id="18" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="11" target="8">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="19" value="调度到操作系统的线程上去运行" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="18">
<mxGeometry x="-0.2478" y="1" relative="1" as="geometry">
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="11" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="140" y="30" width="620" height="110" as="geometry"/>
</mxCell>
<mxCell id="12" value="OS" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="40" y="275" width="60" height="30" as="geometry"/>
</mxCell>
<mxCell id="13" value="Runtime" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="40" y="70" width="60" height="30" as="geometry"/>
</mxCell>
<mxCell id="14" value="协程" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="204" y="70" width="116" height="40" as="geometry"/>
</mxCell>
<mxCell id="15" value="&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;协程&lt;/span&gt;" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="320" y="70" width="116" height="40" as="geometry"/>
</mxCell>
<mxCell id="16" value="&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;协程&lt;/span&gt;" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="436" y="70" width="116" height="40" as="geometry"/>
</mxCell>
<mxCell id="17" value="&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;协程&lt;/span&gt;" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="552" y="70" width="116" height="40" as="geometry"/>
</mxCell>
<mxCell id="20" value="main()" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="286" y="590" width="150" height="60" as="geometry"/>
</mxCell>
<mxCell id="22" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="21" target="20">
<mxGeometry relative="1" as="geometry">
<mxPoint x="450" y="620" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="24" style="edgeStyle=none;html=1;exitX=0;exitY=0.75;exitDx=0;exitDy=0;" edge="1" parent="1" source="21">
<mxGeometry relative="1" as="geometry">
<mxPoint x="440" y="690" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="25" value="defer hook" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="24">
<mxGeometry x="0.1663" y="4" relative="1" as="geometry">
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="21" value="go runtime" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="570" y="570" width="200" height="120" as="geometry"/>
</mxCell>
<mxCell id="23" value="recover" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="289" y="660" width="150" height="60" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>