try

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2022 License: MIT Imports: 2 Imported by: 180

Documentation

Overview

Package try is a new sub package for `try to` functions which replace all of the error checking. The error handlers still stay in the main package err2. For more information see FileCopy example in err2:

...
r := try.To1(os.Open(src))
defer r.Close()

w := try.To1(os.Create(dst))
defer err2.Handle(&err, func() {
	os.Remove(dst)
})
defer w.Close()
try.To1(io.Copy(w, r))
return nil
...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Is

func Is(filter, err error) bool

Is performs filtered error check for the given argument. It's same as To but before throwing an error it checks if error matches the filter. The return value false tells that there are no errors and true that filter is matched.

func IsEOF

func IsEOF(err error) bool

IsEOF checks errors but filters io.EOF from the exception handling and returns boolean which tells if io.EOF is present. See more info from FilterCheck.

func IsEOF1

func IsEOF1[T any](v T, err error) (bool, T)

Is1 performs filtered error check for the given argument. It's same as To but before throwing an error it checks if error matches the filter. The return value false tells that there are no errors and true that filter is matched.

func IsEOF2

func IsEOF2[T, U any](v1 T, v2 U, err error) (bool, T, U)

Is2 performs filtered error check for the given argument. It's same as To but before throwing an error it checks if error matches the filter. The return value false tells that there are no errors and true that filter is matched.

func To

func To(err error)

To is a helper function to call functions which returns (error) and check the error value. If error occurs it panics the error where err2 handlers can catch it if needed.

func To1

func To1[T any](v T, err error) T

To1 is a helper function to call functions which returns (any, error) and check the error value. If error occurs it panics the error where err2 handlers can catch it if needed.

func To2

func To2[T, U any](v1 T, v2 U, err error) (T, U)

To2 is a helper function to call functions which returns (any, any, error) and check the error value. If error occurs it panics the error where err2 handlers can catch it if needed.

func To3

func To3[T, U, V any](v1 T, v2 U, v3 V, err error) (T, U, V)

To3 is a helper function to call functions which returns (any, any, any, error) and check the error value. If error occurs it panics the error where err2 handlers can catch it if needed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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