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 ¶
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 ¶
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.
Click to show internal directories.
Click to hide internal directories.