errors

package
v0.0.0-...-acb8ab4 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2014 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package errors mirrors the standard golang "errors" module. Manipulate errors and provide stack trace information. All golang codes should using this errors package.

Index

Constants

View Source
const (
	DefaultCode = -1
)

Default value if the error code is not defined. The error code is DefaultCode if Error was created by New, Newf, Wrap, Wrapf.

Variables

This section is empty.

Functions

func DefaultError

func DefaultError(e Error) string

A default implementation of the Error method of the error interface.

func Message

func Message(err interface{}) string

This returns the error string without stack trace information.

func StackTrace

func StackTrace() (current, context string)

This returns the current stack trace string.

Types

type Error

type Error interface {

	// This returns the error message without the stack trace.
	Message() string

	// This returns the stack trace without the error message.
	Stack() string

	// This returns the stack trace's context.
	Context() string

	// This returns the error code.
	// If the error code is not pre-defined, return is DefaultCode.
	Code() int

	// This returns the wrapped error. Nil if not wrap another error.
	Inner() error

	// Implements the built-in error interface.
	Error() string
}

Error interface exposes additional information about the error.

func New

func New(msg string) Error

This returns a new baseError initialized with the given message and the current stack trace.

func NewByCode

func NewByCode(code int, msg string) Error

This returns a new baseError initialized with the given message, error code and the current stack trace.

func Newf

func Newf(format string, args ...interface{}) Error

Same as New, but with fmt.Printf-style parameters.

func NewfByCode

func NewfByCode(code int, format string, args ...interface{}) Error

Same as NewByCode, but with fmt.Printf-style parameters.

func Wrap

func Wrap(err error, msg string) Error

Wraps another error in a new baseError.

func WrapByCode

func WrapByCode(code int, err error, msg string) Error

Wraps another error in a new baseError with error code information.

func Wrapf

func Wrapf(err error, format string, args ...interface{}) Error

Same as Wrap, but with fmt.Printf-style parameters.

func WrapfByCode

func WrapfByCode(code int, err error, format string, args ...interface{}) Error

Same as WrapByCode, but with fmt.Printf-style parameters.

Jump to

Keyboard shortcuts

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