Standard library / net

net.OpError

Wrap an operation failure with Op, Net, Source, Addr and Err. Use errors.As for structured metadata and errors.Is to test wrapped causes. Expected stdout: 'true dial\n'.

Formal Syntax & Structure

go syntaxgo
type OpError struct {  Op string
  Net string
  Source Addr
  Addr Addr
  Err error}

Working Example

Example Snippetgo
package main
import (  "errors"  "fmt"  "net")
func main() {  _, e := net.Dial("not-a-network", "demo")  var op *net.OpError  fmt.Println(errors.As(e, &op), op.Op)}
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference