mirror of
https://github.com/tursom/GoCollections.git
synced 2026-08-19 13:33:29 +08:00
28 lines
532 B
Go
28 lines
532 B
Go
package exceptions
|
|
|
|
type IndexOutOfBound struct {
|
|
RuntimeException
|
|
}
|
|
|
|
func NewIndexOutOfBound(message interface{}, config *ExceptionConfig) *IndexOutOfBound {
|
|
config.AddSkipStack(1)
|
|
return &IndexOutOfBound{
|
|
NewRuntimeException(
|
|
message,
|
|
"exception caused IndexOutOfBound:",
|
|
config,
|
|
),
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|