Skip to content

Commit 240b5f0

Browse files
committed
运行时的异常处理
1 parent 846611e commit 240b5f0

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

cmd/commons/core/runner.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ func Start(u string, hashmap map[string]interface{}, i int, c chan int) {
106106
}()
107107
attack.Sevice(target, hashmap)
108108

109+
defer func() {
110+
if errs := recover(); errs != nil {
111+
log.Debug("Runner panic: ", errs)
112+
}
113+
}()
109114
// 放到最后,不然无法生效
110115
c <- i + 1
111116

cmd/test/checkerr.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func getErr(int1, int2 int) error {
6+
defer func() {
7+
if err := recover(); err != nil {
8+
fmt.Println(err)
9+
}
10+
}()
11+
_ = int1 / int2
12+
return nil
13+
}
14+
15+
func main() {
16+
defer func() {
17+
if err := recover(); err != nil {
18+
fmt.Println(err)
19+
}
20+
}()
21+
_ = getErr(1, 0)
22+
fmt.Println("Hello, playground")
23+
24+
}

0 commit comments

Comments
 (0)