mirror of
https://github.com/tursom/GoCollections.git
synced 2025-03-13 17:00:18 +08:00
27 lines
516 B
Go
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
|
|
}
|