10 examples of 'golang recover' in Go

Every line of 'golang recover' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
333func test8b() (r int) {
334 defer varargs(&r, 4, 5, 6)
335 return
336}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

3139func (p *morsecodeParser) T() (localctx ITContext) {
3140 localctx = NewTContext(p, p.GetParserRuleContext(), p.GetState())
3141 p.EnterRule(localctx, 42, morsecodeParserRULE_t)
3142
3143 defer func() {
3144 p.ExitRule()
3145 }()
3146
3147 defer func() {
3148 if err := recover(); err != nil {
3149 if v, ok := err.(antlr.RecognitionException); ok {
3150 localctx.SetException(v)
3151 p.GetErrorHandler().ReportError(p, v)
3152 p.GetErrorHandler().Recover(p, v)
3153 } else {
3154 panic(err)
3155 }
3156 }
3157 }()
3158
3159 p.EnterOuterAlt(localctx, 1)
3160 {
3161 p.SetState(199)
3162 p.Match(morsecodeParserDASH)
3163 }
3164
3165 return localctx
3166}
6func RecoverDemo1() {
7 defer func() {
8 if err := recover(); err != nil {
9 fmt.Println("A")
10 }
11 }()
12
13 panic("demo")
14 fmt.Println("B")
15}
81func RecoverDemo6() {
82 defer func() {
83 if err := recover(); err != nil {
84 fmt.Println("A")
85 }
86 }()
87
88 panic(nil)
89 fmt.Println("B")
90}
28func main(){
29 didPanic := throwsPanic(check_user)
30 fmt.Println("didPanic =", didPanic)
31}
688func f41(p, q *int) (r *int) { // ERROR "live at entry to f41: p q$"
689 r = p
690 defer func() { // ERROR "live at call to deferproc: q r$" "live at call to deferreturn: r$"
691 recover()
692 }()
693 printint(0) // ERROR "live at call to printint: q r$"
694 r = q
695 return // ERROR "live at call to deferreturn: r$"
696}
70func main() {
71 shouldfail(badlen, "badlen")
72 shouldfail(biglen, "biglen")
73 shouldfail(badcap, "badcap")
74 shouldfail(badcap1, "badcap1")
75 shouldfail(bigcap, "bigcap")
76 shouldfail(badchancap, "badchancap")
77 shouldfail(bigchancap, "bigchancap")
78 shouldfail(overflowchan, "overflowchan")
79}
8func main() {
9 err := recover()
10 println(err)
11}
11func main() {
12 n := int64(100)
13 x := make([]int, n)
14 x[99] = 234;
15 z := x[n-1]
16 if z != 234 {
17 println("BUG")
18 }
19 n |= 1<<32
20 defer func() {
21 recover()
22 }()
23 z = x[n-1]
24 println("BUG2")
25}
20func (this ErrorHandler) Recover(p antlr.Parser, r antlr.RecognitionException) {
21 os.Exit(1)
22}

Related snippets