1
0
mirror of https://github.com/tursom/GoCollections.git synced 2025-03-17 03:20:15 +08:00
GoCollections/exceptions/NPE.go

25 lines
493 B
Go
Raw Normal View History

2021-05-21 11:14:07 +08:00
package exceptions
2022-03-28 18:19:05 +08:00
import (
"github.com/tursom/GoCollections/lang"
"reflect"
)
2021-05-21 11:14:07 +08:00
type NPE struct {
RuntimeException
}
2022-03-31 01:22:30 +08:00
func NewNPE(message string, config *ExceptionConfig) *NPE {
2022-03-21 11:02:41 +08:00
return &NPE{
2022-04-02 15:25:35 +08:00
NewRuntimeException(message, config.AddSkipStack(1).
SetExceptionName("github.com.tursom.GoCollections.exceptions.NPE")),
2021-05-21 11:14:07 +08:00
}
}
2022-03-28 18:19:05 +08:00
func CheckNil[T any](p *T) {
t := reflect.TypeOf(lang.Nil[T]())
if p == nil {
panic(NewNPE(t.Name()+" is null", DefaultExceptionConfig().AddSkipStack(1)))
}
}