-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
982cb9c
commit 7deceaf
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import( | ||
"fmt" | ||
"log" | ||
) | ||
|
||
func main(){ | ||
fmt.Println("start") | ||
panicker() | ||
fmt.Println("end") | ||
} | ||
|
||
func panicker(){ | ||
fmt.Println("about to panic") | ||
defer func(){ | ||
if err := recover(); err != nil { | ||
log.Println("Error:", err) | ||
// if the error is serious we can re-panic | ||
// in that case the main function will panic as well | ||
// without the panic, only this internal function will stop executing | ||
// main will live on and print the "end" text | ||
//panic(err) | ||
} | ||
}() | ||
panic("something bad happened") | ||
fmt.Println("done panicking") | ||
} |