exceptions

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package exceptions define a interface for Output Specific Errors of Internal Projects and Implementation of CommonException

Index

Constants

View Source
const CommonExceptionCode = 819

Variables

This section is empty.

Functions

func CallStack

func CallStack() []string

CallStack 获取调用堆栈

func IsException

func IsException(err error) bool

IsIException 用于判断 error 是否为自定义的 IException 接口

Types

type CommonException

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

CommonException 是实现Exception接口的基础异常结构 常规异常可通过参数的不同直接实例化此结构来支持业务错误的定义 更高级的归类可嵌入结构体实现

func (*CommonException) Code

func (e *CommonException) Code() int

Code 获取异常所对应的错误业务异常Code

func (*CommonException) Error

func (e *CommonException) Error() string

Error 将异常信息输出为JSON字符串,以用于传输后的进一步处理

func (*CommonException) Message

func (e *CommonException) Message() string

Message 获取异常所对应的错误业务异常消息

type Exception

type Exception interface {
	// Error implementing golang's own error interface
	Error() string
	// Code gets the Code of exceptions, eg 1000001
	Code() int
	// Message gets the message of exception
	Message() string
}

Exception define a custom exceptions interfaces for tmi internal projects

func Code

func Code(code int, message string) Exception

Code 创建一个自定义Code的异常

func CodeF

func CodeF(code int, format string, args ...interface{}) Exception

CodeF 创建一个自定义Code的异常

func New

func New(message string) Exception

New 创建一个Code为819的常规异常,如需要自定义code,请使用 exceptions.Code

func NewF

func NewF(format string, args ...interface{}) Exception

NewF 创建一个Code为819的常规异常,如需要自定义code,请使用 exceptions.Code

Jump to

Keyboard shortcuts

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