mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-13 07:23:39 +00:00
runtime: print error when panicking with error interface type
This commit is contained in:
committed by
Ron Evans
parent
0fd90c49cc
commit
024eceb476
@@ -4,6 +4,10 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type stringer interface {
|
||||||
|
String() string
|
||||||
|
}
|
||||||
|
|
||||||
//go:nobounds
|
//go:nobounds
|
||||||
func printstring(s string) {
|
func printstring(s string) {
|
||||||
for i := 0; i < len(s); i++ {
|
for i := 0; i < len(s); i++ {
|
||||||
@@ -199,8 +203,44 @@ func printnl() {
|
|||||||
|
|
||||||
func printitf(msg interface{}) {
|
func printitf(msg interface{}) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
|
case bool:
|
||||||
|
print(msg)
|
||||||
|
case int:
|
||||||
|
print(msg)
|
||||||
|
case int8:
|
||||||
|
print(msg)
|
||||||
|
case int16:
|
||||||
|
print(msg)
|
||||||
|
case int32:
|
||||||
|
print(msg)
|
||||||
|
case int64:
|
||||||
|
print(msg)
|
||||||
|
case uint:
|
||||||
|
print(msg)
|
||||||
|
case uint8:
|
||||||
|
print(msg)
|
||||||
|
case uint16:
|
||||||
|
print(msg)
|
||||||
|
case uint32:
|
||||||
|
print(msg)
|
||||||
|
case uint64:
|
||||||
|
print(msg)
|
||||||
|
case uintptr:
|
||||||
|
print(msg)
|
||||||
|
case float32:
|
||||||
|
print(msg)
|
||||||
|
case float64:
|
||||||
|
print(msg)
|
||||||
|
case complex64:
|
||||||
|
print(msg)
|
||||||
|
case complex128:
|
||||||
|
print(msg)
|
||||||
case string:
|
case string:
|
||||||
print(msg)
|
print(msg)
|
||||||
|
case error:
|
||||||
|
print(msg.Error())
|
||||||
|
case stringer:
|
||||||
|
print(msg.String())
|
||||||
default:
|
default:
|
||||||
// cast to underlying type
|
// cast to underlying type
|
||||||
itf := *(*_interface)(unsafe.Pointer(&msg))
|
itf := *(*_interface)(unsafe.Pointer(&msg))
|
||||||
|
|||||||
Reference in New Issue
Block a user