mirror of
https://github.com/tursom/GoCollections.git
synced 2025-02-26 12:03:21 +08:00
function try add generic support
This commit is contained in:
parent
67220737dc
commit
47dd188d72
@ -55,10 +55,10 @@ func BuildStackTrace(builder *strings.Builder, e Exception, exceptionMsg string)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Try(
|
func Try[R any](
|
||||||
f func() (ret interface{}, err Exception),
|
f func() (ret R, err Exception),
|
||||||
catch func(panic interface{}) (ret interface{}, err Exception),
|
catch func(panic interface{}) (ret R, err Exception),
|
||||||
) (ret interface{}, err Exception) {
|
) (ret R, err Exception) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
ret, err = catch(r)
|
ret, err = catch(r)
|
||||||
|
Loading…
Reference in New Issue
Block a user