1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 21:02:27 +08:00
Files
lancet/docs/xerror.md
2022-03-17 11:33:45 +08:00

1.0 KiB

Xerror

Package xerror implements helpers for errors.

Source:

Usage:

import (
    "github.com/duke-git/lancet/v2/xerror"
)

Index

Documentation

Unwrap

Unwrap if err is nil then it returns a valid value. If err is not nil, Unwrap panics with err.

Signature:

func Unwrap[T any](val T, err error) T

Example:

package main

import (
    "fmt"
    "github.com/duke-git/lancet/v2/xerror"
)

func main() {
    _, err := strconv.Atoi("4o2")
	defer func() {
		v := recover()
		fmt.Println(err.Error()) // err.Error() == v.(*strconv.NumError).Error()
	}()

	xerror.Unwrap(strconv.Atoi("4o2"))
}