You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.7 KiB

1 year ago
// =============================================================================
// Active-GO Framework
// Copyright (c) 2025 ActiveThing (https://activething.com)
// Author: Juan V. Navarro juanvnl@activething.com
// =============================================================================
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// =============================================================================
// Date Create 13/05/2025
// =============================================================================
package errs
const (
// errPanic is the error class name used to represent panics converted to errors.
1 year ago
errPanic = moduleName + "panic"
)
type (
// PanicErr is an error type that wraps a recovered panic.
// It allows treating a panic as a structured error.
1 year ago
PanicErr struct {
Err // Embeds the Err type to inherit its methods and basic structure.
cause error // cause stores the recovered panic value, converted to an error type.
1 year ago
}
)
// CreatePanicErr creates a new PanicErr instance from a recovered panic value.
// It converts the panic value to an error type using ToError.
1 year ago
func CreatePanicErr(cause any) PanicErr {
return PanicErr{
Err: CreateErr(errPanic), // Creates a base error with the "panic" class.
cause: ToError(cause), // Converts the panic value to an error.
1 year ago
}
}
// Cause implements the Causer interface for PanicErr.
// It returns the underlying error representing the panic value.
1 year ago
func (e PanicErr) Cause() error { return e.cause }
// Unwrap implements Go 1.13+'s errors.Unwrap interface.
// It returns the underlying error representing the panic value, allowing
// the PanicErr to be unwrapped to access the original cause.
1 year ago
func (e PanicErr) Unwrap() error { return e.cause }

Powered by TurnKey Linux.