GoCollections/exceptions/IndexOutOfBoundError.go
2022-03-28 18:19:05 +08:00

27 lines
516 B
Go

package exceptions
type IndexOutOfBound struct {
RuntimeException
}
func NewIndexOutOfBound(message any, config *ExceptionConfig) *IndexOutOfBound {
return &IndexOutOfBound{
NewRuntimeException(
message,
"exception caused IndexOutOfBound:",
config.AddSkipStack(1),
),
}
}
func CatchIndexOutOfBound[T any](f func() T, config *ExceptionConfig) (r T, err Exception) {
defer func() {
r := recover()
if r != nil {
err = NewIndexOutOfBound(r, config.AddSkipStack(3))
}
}()
r = f()
return
}