github.com/tursom/GoCollections@v0.3.10/exceptions/IndexOutOfBoundError.go (about) 1 /* 2 * Copyright (c) 2022 tursom. All rights reserved. 3 * Use of this source code is governed by a GPL-3 4 * license that can be found in the LICENSE file. 5 */ 6 7 package exceptions 8 9 type IndexOutOfBound struct { 10 RuntimeException 11 } 12 13 func NewIndexOutOfBound(message string, config *ExceptionConfig) *IndexOutOfBound { 14 return &IndexOutOfBound{ 15 *NewRuntimeException(message, config.AddSkipStack(1). 16 SetExceptionName("github.com.tursom.GoCollections.exceptions.IndexOutOfBound")), 17 } 18 } 19 20 func CatchIndexOutOfBound[T any](f func() T, config *ExceptionConfig) (r T, err Exception) { 21 defer func() { 22 r := recover() 23 if r != nil { 24 err = NewIndexOutOfBound("", config.AddSkipStack(3).SetCause(r)) 25 } 26 }() 27 r = f() 28 return 29 }