Skip to content

runtime: PanicNilError error string should have "runtime error: " prefix #63813

@Goclipse27

Description

@Goclipse27

What version of Go are you using (go version)?

$ go version
1.21.3

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
Windows, amd64, 1.21.3

What did you do?

package main

import (
	"fmt"
	"runtime"
)

type I interface {
	M()
}

func main() {

	defer func() {
		if r := recover(); r != nil {
			if e, ok := r.(runtime.Error); ok {
				fmt.Println(e.Error())
			}
		}
	}()

	defer func() {
		if r := recover(); r != nil {
			if e, ok := r.(runtime.Error); ok {
				fmt.Println(e.Error())
				panic(nil)
			}
		}
	}()

	defer func() {
		if r := recover(); r != nil {
			if e, ok := r.(runtime.Error); ok {
				fmt.Println(e.Error())
				a := 1
				b := 0

				fmt.Println(a / b)
			}
		}
	}()

	var i I
	i.M()

	//panic(nil)

	//fmt.Println("hello")

}

What did you expect to see?

Since Panic error is a different runtime error as mentioned in the documentation - https://pkg.go.dev/builtin#panic and it has implementation of method - RuntimeError
// RuntimeError is a no-op function but // serves to distinguish types that are run time // errors from ordinary errors: a type is a // run time error if it has a RuntimeError method. RuntimeError()

I would like to see the error message like other runtime errors - "runtime error:" as mentioned in the above example

What did you see instead?

I rather the see the error message as - panic called with nil argument

Metadata

Metadata

Assignees

Labels

NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

In Progress

Relationships

None yet

Development

No branches or pull requests

Issue actions