xerror

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package xerror implements helpers for errors

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unwrap

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

Unwrap if err is nil then it returns a valid value If err is not nil, Unwrap panics with err. Play: https://go.dev/play/p/w84d7Mb3Afk

Example
result1 := Unwrap(strconv.Atoi("42"))
fmt.Println(result1)

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

Unwrap(strconv.Atoi("4o2"))
Output:

42
true

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL