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(
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user