mirror of
https://github.com/tursom/GoCollections.git
synced 2025-03-13 17:00:18 +08:00
23 lines
529 B
Go
23 lines
529 B
Go
package exceptions
|
|
|
|
type IndexOutOfBound struct {
|
|
RuntimeException
|
|
}
|
|
|
|
func NewIndexOutOfBound(message string, config *ExceptionConfig) *IndexOutOfBound {
|
|
return &IndexOutOfBound{
|
|
NewRuntimeException(message, config.AddSkipStack(1).SetExceptionName("IndexOutOfBound")),
|
|
}
|
|
}
|
|
|
|
func CatchIndexOutOfBound[T any](f func() T, config *ExceptionConfig) (r T, err Exception) {
|
|
defer func() {
|
|
r := recover()
|
|
if r != nil {
|
|
err = NewIndexOutOfBound("", config.AddSkipStack(3).SetCause(PackageAny(r)))
|
|
}
|
|
}()
|
|
r = f()
|
|
return
|
|
}
|