exception

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package exception provides helper functions to facilitate work with errors, stack traces or handling panics.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aggregatef

func Aggregatef(errors ...error) error

Aggregatef returns formatted array of errors as single error.

Example
package main

import (
	"errors"
	"fmt"

	"github.com/Prastiwar/Go-flow/exception"
)

func main() {
	aggErr := exception.Aggregatef(
		errors.New("'' is not valid value for title"),
		errors.New("title is required"),
	)
	err := fmt.Errorf("validation: %w", aggErr)
	fmt.Println(err)

}
Output:
validation: ["'' is not valid value for title", "title is required"]

func ConvertToError

func ConvertToError(i any) error

ConvertToError returns i if it's error or new error string.

func HandlePanicError

func HandlePanicError(onPanic func(error))

HandlePanicError defers function which check for recover() and convert it to error preserving error type or creating new string error. If recover() is nil onPanic will not be called.

Example
package main

import (
	"fmt"

	"github.com/Prastiwar/Go-flow/exception"
)

func main() {
	defer exception.HandlePanicError(func(err error) {
		fmt.Println(err)
	})

	panic("string error")

}
Output:
string error

func StackTrace

func StackTrace() string

StackTrace returns a formatted string stack trace of the goroutine that calls it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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