mirror of
https://github.com/samber/lo.git
synced 2026-04-22 15:37:14 +08:00
fa095e4b4f
* fix(doc): fix go playground demo URL * fix(doc): add more go playground demo URL
1.3 KiB
1.3 KiB
name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | playUrl | variantHelpers | similarHelpers | position | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| TryX | tryx | errors.go#L118 | core | error-handling |
|
https://go.dev/play/p/mTyyWUvn9u4 |
|
|
20 |
Calls a function and returns false in case of error or panic. Variants cover callbacks returning 0 to 6 values.
ok := lo.Try(func() error {
// return an error to mark failure
return fmt.Errorf("boom")
})
// ok == false
ok = lo.Try0(func() {
// panics are caught and return false
panic("boom")
})
// ok == false
ok = lo.Try2(func() (int, error) {
return 42, nil
})
// ok == true