compiler, runtime: make slice lookup panics recoverable

This commit is contained in:
Ayke van Laethem
2025-02-26 12:38:06 +01:00
parent 88d273da97
commit 98d55ab070
5 changed files with 19 additions and 11 deletions
+11
View File
@@ -32,6 +32,7 @@ func main() {
println("\n# runtime panics")
runtimePanicDivByZero(1, 0)
runtimePanicLookup([]int{1, 2, 3}, 10)
println("\n# runtime.Goexit")
runtimeGoexit()
@@ -127,6 +128,16 @@ func runtimePanicDivByZero(a, b int) int {
return a / b
}
func runtimePanicLookup(slice []int, index int) int {
defer func() {
if err := recover(); err != nil {
println("recovered:", err)
}
}()
return slice[index]
}
func runtimeGoexit() {
wg.Add(1)
go func() {