mirror of
https://github.com/tursom/GoCollections.git
synced 2025-03-13 17:00:18 +08:00
29 lines
606 B
Go
29 lines
606 B
Go
package exceptions
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/tursom/GoCollections/lang"
|
|
"reflect"
|
|
)
|
|
|
|
type TypeCastException struct {
|
|
RuntimeException
|
|
}
|
|
|
|
func NewTypeCastException(message any, config *ExceptionConfig) *TypeCastException {
|
|
return &TypeCastException{
|
|
NewRuntimeException(
|
|
message,
|
|
"exception caused ElementNotFoundException:",
|
|
config.AddSkipStack(1),
|
|
),
|
|
}
|
|
}
|
|
|
|
func NewTypeCastExceptionByType[T any](obj any, config *ExceptionConfig) *TypeCastException {
|
|
return NewTypeCastException(
|
|
fmt.Sprintf("object %s cannot cast to %s", obj, reflect.TypeOf(lang.Nil[T]()).Name()),
|
|
config,
|
|
)
|
|
}
|