mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-18 15:02:09 +00:00
30 lines
350 B
Go
30 lines
350 B
Go
package panic
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestPanic2Err(t *testing.T) {
|
|
err := CatchFunc()
|
|
if err != nil {
|
|
fmt.Print(err)
|
|
}
|
|
}
|
|
|
|
func CatchFunc() (err error) {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
err = errors.New(r.(string))
|
|
}
|
|
}()
|
|
|
|
PanicFunc()
|
|
return nil
|
|
}
|
|
|
|
func PanicFunc() {
|
|
panic("Something is wrong!")
|
|
}
|