goerror

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: BSD-3-Clause Imports: 2 Imported by: 0

README

Go Errors

Go Errors is a package for handling errors in Go. It provides a simple and flexible way to create, handle and manage errors in your code.

Installation

To use Go Errors in your Go project, you need to install it using Go modules. Run the following command in your terminal:

go get github.com/start-codex/errors

Usage

Creating an error

To create an error, you can use the New function. It takes a message and an optional code as arguments and returns a new error:

err := goerror.New("An error occurred", "ERR-001")
Handling an error

To handle an error, you can use the DeferError function. It takes a callback function as an argument and calls it with the recovered error and stack trace:

goerror.DeferError(func (err error, stackTrace string) {
    log.Printf("Error: %v\nStack Trace: %s", err, stackTrace)
})
Getting the stack trace

To get the stack trace of an error, you can use the GetStackTrace function. It returns a string with the stack trace of the error:

stackTrace := err.GetStackTrace()
Getting the error message and code

To get the message and code of an error, you can use the Message and Code methods respectively:

message := err.Message()
code := err.Code()

License

Go Errors is licensed under the BSD3 License. See LICENSE for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeferError

func DeferError(callback func(err error, stackTrace string))

DeferError is a function that recovers from a panic and calls the callback function.

Types

type Err

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

Err is a struct that implements the error interface.

func FromError

func FromError(e error) (err Err)

FromError returns a new error from an error.

func New

func New(message string, code ...string) (err Err)

New returns a new error.

func (*Err) Code

func (e *Err) Code() string

Code returns the code of the error.

func (*Err) Error

func (e *Err) Error() string

Error returns the message of the error.

func (*Err) GetStackTrace

func (e *Err) GetStackTrace() string

GetStackTrace returns the stack trace of the error.

func (*Err) ToError

func (e *Err) ToError() error

ToError returns the error as an error.

type Error

type Error string

Error is a string that implements the error interface.

func (Error) Error

func (e Error) Error() string

Error is a string that implements the error interface.

func (*Error) GetStackTarce

func (e *Error) GetStackTarce() string

GetStackTarce GetStackTrace returns the stack trace of the error.

Jump to

Keyboard shortcuts

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