mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 11:07:46 +00:00
compiler, runtime: make slice lookup panics recoverable
This commit is contained in:
Vendored
+11
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user