GoCollections/exceptions/IndexOutOfBoundError.go

30 lines
724 B
Go
Raw Normal View History

2022-11-25 18:19:33 +08:00
/*
* Copyright (c) 2022 tursom. All rights reserved.
* Use of this source code is governed by a GPL-3
* license that can be found in the LICENSE file.
*/
2021-05-20 17:32:35 +08:00
package exceptions
type IndexOutOfBound struct {
2021-05-21 10:31:49 +08:00
RuntimeException
2021-05-20 17:32:35 +08:00
}
2022-03-31 01:22:30 +08:00
func NewIndexOutOfBound(message string, config *ExceptionConfig) *IndexOutOfBound {
2022-03-21 11:02:41 +08:00
return &IndexOutOfBound{
*NewRuntimeException(message, config.AddSkipStack(1).
2022-04-02 15:25:35 +08:00
SetExceptionName("github.com.tursom.GoCollections.exceptions.IndexOutOfBound")),
2021-05-20 17:32:35 +08:00
}
}
2022-03-21 11:02:41 +08:00
func CatchIndexOutOfBound[T any](f func() T, config *ExceptionConfig) (r T, err Exception) {
defer func() {
r := recover()
if r != nil {
2022-04-02 15:25:35 +08:00
err = NewIndexOutOfBound("", config.AddSkipStack(3).SetCause(r))
2022-03-21 11:02:41 +08:00
}
}()
r = f()
return
}