errors

package
v0.0.0-...-1781da9 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2014 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

errors包的简单扩展,增加了错误代码和嵌套错误的功能

err := errors.Newf(5, nil, "错误代码%v", 5)
err2 := errors.New(6, err, "嵌套错误")
err3 := err2.GetPrevious()

Index

Examples

Constants

View Source
const Version = "0.1.2.140819"

当前库的版本

Variables

This section is empty.

Functions

This section is empty.

Types

type Errors

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

func New

func New(code int, previous error, s string) *Errors
Example
package main

import (
	"fmt"

	"github.com/caixw/lib.go/errors"
)

func main() {
	err := errors.New(5, nil, "abc")
	if err != nil {
		fmt.Print(err.GetCode())
	}

}
Output:

5

func Newf

func Newf(code int, previous error, format string, args ...interface{}) *Errors

带格式化的New

Example
package main

import (
	"fmt"

	"github.com/caixw/lib.go/errors"
)

func main() {
	err := errors.Newf(5, nil, "code=[%v]", 5)
	err2 := errors.New(6, err, "abc")
	if err2 != nil && err2.GetPrevious() != nil {
		fmt.Print(err2.GetPrevious())
	}

}
Output:

code=[5]

func (*Errors) Error

func (e *Errors) Error() string

func (*Errors) GetCode

func (e *Errors) GetCode() int

返回错误代码。

func (*Errors) GetPrevious

func (e *Errors) GetPrevious() *Errors

返回错误链接中的前一个错误,若没有,则返回nil。

Jump to

Keyboard shortcuts

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