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 ¶
- func Is(filter, err error) bool
- func IsEOF(err error) bool
- func IsEOF1[T any](v T, err error) (bool, T)
- func IsEOF2[T, U any](v1 T, v2 U, err error) (bool, T, U)
- func To(err error)
- func To1[T any](v T, err error) T
- func To2[T, U any](v1 T, v2 U, err error) (T, U)
- func To3[T, U, V any](v1 T, v2 U, v3 V, err error) (T, U, V)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Is ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
Types ¶
This section is empty.