github.com/tursom/GoCollections@v0.3.10/exceptions/NPE.go (about)

     1  /*
     2   * Copyright (c) 2022 tursom. All rights reserved.
     3   * Use of this source code is governed by a GPL-3
     4   * license that can be found in the LICENSE file.
     5   */
     6  
     7  package exceptions
     8  
     9  import (
    10  	"reflect"
    11  
    12  	"github.com/tursom/GoCollections/lang"
    13  )
    14  
    15  type NPE struct {
    16  	RuntimeException
    17  }
    18  
    19  func NewNPE(message string, config *ExceptionConfig) *NPE {
    20  	return &NPE{
    21  		*NewRuntimeException(message, config.AddSkipStack(1).
    22  			SetExceptionName("github.com.tursom.GoCollections.exceptions.NPE")),
    23  	}
    24  }
    25  
    26  func CheckNil[T any](p *T) {
    27  	t := reflect.TypeOf(lang.Nil[T]())
    28  	if p == nil {
    29  		panic(NewNPE(t.Name()+" is null", DefaultExceptionConfig().AddSkipStack(1)))
    30  	}
    31  }