""
package main
import(
"fmt"
"runtime"
"regexp"
)
var re_runtimepanicdetector *regexp.Regexp = regexp.MustCompile("runtime/panic.go$");
func tester_for_panic( deferdepth int )bool{
_,file,_,_ := runtime.Caller(deferdepth+3)
return re_runtimepanicdetector.MatchString(file)
}
func tester_for_panic_worktest() bool {
defer func(){
recover() ;
if !tester_for_panic(0) { panic("tester_for_panic: NOT WORK!!") }
}();
panic(1)
}
var Iswork_tester_for_panic bool= tester_for_panic_worktest();
func testp( dopanic bool ) {
defer func() {
fmt.Println("defer panic=", tester_for_panic(0)) ;
recover()
}()
if (dopanic) { panic("test") }
}
func main(){
testp(true)
testp(false)
}
source
share