Standard library / runtime

runtime.TypeAssertionError.Error()

Return a diagnostic for a failed type assertion. The exact text is not a stable machine-readable contract. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func (e *TypeAssertionError) Error() string

Return Value

string

Diagnostic string describing the failed assertion.

Working Example

Example Snippetgo
package main
import (  "fmt"  "runtime")
func main() {  func() {    defer func() {      e, ok := recover().(*runtime.TypeAssertionError)      fmt.Println(ok && e != nil && e.Error() != "")    }()    var x any = 42    _ = x.(string)  }()}
Go Reference