mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
25 lines
319 B
Go
25 lines
319 B
Go
|
package goStrongswanVici
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
)
|
||
|
|
||
|
func handlePanic(f func() error) (err error) {
|
||
|
defer func() {
|
||
|
r := recover()
|
||
|
//no panic
|
||
|
if r == nil {
|
||
|
return
|
||
|
}
|
||
|
//panic a error
|
||
|
if e, ok := r.(error); ok {
|
||
|
err = e
|
||
|
return
|
||
|
}
|
||
|
//panic another stuff
|
||
|
err = fmt.Errorf("%s", r)
|
||
|
}()
|
||
|
err = f()
|
||
|
return
|
||
|
}
|