errors

package
v0.0.0-...-5a8c9f9 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2016 License: MIT Imports: 3 Imported by: 3

Documentation

Overview

Package errors provides helper functions and structures for more natural error handling in some situations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsEx

func AsEx(err error) error

Convert an error to an exception. This function doesn't do anything with nil errors and errors which are already exceptions.

func New

func New(text string) error

Convenience function to call errors.New() from the standart library.

func Stack

func Stack(i int) string

Stack returns a formatted stack trace of the goroutine that calls it. The argument skip is the number of stack frames to ascend

Types

type ErrorList

type ErrorList struct {
	// contains filtered or unexported fields
}

An error which is a list of errors. It's intended to be used locally in a function to aggregate errors from different calls. Here is a typical use case:

type aggregator struct {
	val1 io.Closer
	val2 io.Closer
	vals []io.Closer
}

func (self *aggregator) Close() error {
	errs := errors.List().
		Add(self.val1.Close()).
		Add(self.val2.Close())
	for _, v := range self.vals {
		errs.Add(v.Close())
	}
	return errs.Err()
}

func AsList

func AsList(errs ...error) *ErrorList

Create an error list from errors. Nil errors and other error lists are added as in Add.

func List

func List() *ErrorList

Create an empty error list.

func (*ErrorList) Add

func (self *ErrorList) Add(err error) *ErrorList

Add an error to the list. This function ignores nil errors and inlines other error lists so that you don't have error lists of error lists.

func (*ErrorList) AddAll

func (self *ErrorList) AddAll(errs []error) *ErrorList

Add all errors from the array to the error list. Nil errors and other error lists are added as in Add.

func (*ErrorList) Err

func (self *ErrorList) Err() error

Simplify the error list. This function gives nil for empty error list and a single error for the error list of length one.

func (*ErrorList) Error

func (self *ErrorList) Error() string

Implementation of an error interface for error list.

type ExError

type ExError struct {
	// contains filtered or unexported fields
}

An exception: an error with the stack trace, similar to the exceptions in other languages like Java.

func Ex

func Ex(s string) ExError

A function to create an exception from an error message.

func WrapEx

func WrapEx(err error) ExError

Wrap an error into an exception.

func (ExError) Error

func (self ExError) Error() string

Implementation of an error interface for exception.

func (ExError) Reason

func (self ExError) Reason() error

Get the underlying error from the exception.

Jump to

Keyboard shortcuts

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