]> Cypherpunks repositories - gostls13.git/commit
runtime: during panic, print value instead of address, if kind is printable
authorEmmanuel T Odeke <emmanuel@orijtech.com>
Mon, 2 Mar 2020 01:41:44 +0000 (17:41 -0800)
committerEmmanuel Odeke <emm.odeke@gmail.com>
Tue, 3 Mar 2020 02:34:32 +0000 (02:34 +0000)
commit972df38445977cc04414c7b6f469e2a8e5a63861
tree12826d92812bda0263e4385aca233a476b83b2c3
parent2001685ec01c240eda84762a3bc612ddd3ca93fe
runtime: during panic, print value instead of address, if kind is printable

Make panics more useful by printing values, if their
underlying kind is printable, instead of just their memory address.

Thus now given any custom type derived from any of:
    float*, int*, string, uint*

if we have panic with such a result, its value will be printed.

Thus given any of:
    type MyComplex128 complex128
    type MyFloat64 float64
    type MyString string
    type MyUintptr uintptr

    panic(MyComplex128(32.1 + 10i))
    panic(MyFloat64(-93.7))
    panic(MyString("This one"))
    panic(MyUintptr(93))

They will now print in the panic:

    panic: main.MyComplex64(+1.100000e-001+3.000000e+000i)
    panic: main.MyFloat64(-9.370000e+001)
    panic: main.MyString("This one")
    panic: main.MyUintptr(93)

instead of:

    panic: (main.MyComplex128) (0xe0100,0x138cc0)
    panic: (main.MyFloat64) (0xe0100,0x138068)
    panic: (main.MyString) (0x48aa00,0x4c0840)
    panic: (main.MyUintptr) (0xe0100,0x137e58)

and anything else will be printed as in the past with:

    panic: (main.MyStruct) (0xe4ee0,0x40a0e0)

Also while here, updated the Go1.15 release notes.

Fixes #37531

Change-Id: Ia486424344a386014f2869ab3483e42a9ef48ac4
Reviewed-on: https://go-review.googlesource.com/c/go/+/221779
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
doc/go1.15.html
src/runtime/error.go
src/runtime/panic_test.go [new file with mode: 0644]
src/runtime/testdata/testprog/panicprint.go [new file with mode: 0644]