运行时恐慌

Run-time panics 运行时恐慌

原文:https://go.dev/ref/spec#Run-time_panics

Execution errors such as attempting to index an array out of bounds trigger a run-time panic equivalent to a call of the built-in function panic with a value of the implementation-defined interface type runtime.Error. That type satisfies the predeclared interface type error. The exact error values that represent distinct run-time error conditions are unspecified.

​ 执行错误,如尝试对数组进行越界索引,会触发一个运行时panic,相当于调用内置函数panic,并传入实现定义的接口类型runtime.Error的值。该类型满足预声明的接口类型error。表示不同运行时错误条件的确切错误值未指定。

1
2
3
4
5
6
package runtime

type Error interface {
	error
	// and perhaps other methods
}
最后修改 March 10, 2025: 更新 (8b0292e5)