function try add generic support

This commit is contained in:
tursom 2022-03-21 11:58:21 +08:00
parent 67220737dc
commit 47dd188d72

View File

@ -55,10 +55,10 @@ func BuildStackTrace(builder *strings.Builder, e Exception, exceptionMsg string)
}
}
func Try(
f func() (ret interface{}, err Exception),
catch func(panic interface{}) (ret interface{}, err Exception),
) (ret interface{}, err Exception) {
func Try[R any](
f func() (ret R, err Exception),
catch func(panic interface{}) (ret R, err Exception),
) (ret R, err Exception) {
defer func() {
if r := recover(); r != nil {
ret, err = catch(r)