--------------------------Process Control up to-----------------------------Package Mainimport"FMT"func explode () {//cause a panic.Panic"wrong")}func throwpanic (f func ()) {defer func () {ifERR: = Recover (); Err! =Nil {//Handle our error.Fmt. Println ("FIX") fmt. Println ("ERR", Err)} } () f () fmt. Println ("Finish")}func Main () {throwpanic (explode) fmt. Println ("reach here")//up to}--------------------------Process Control is not up to-----------------------------Package Mainimport"FMT"func explode () {//cause a panic.Panic"wrong")}func Main () {//Handle errors in defer func with recover.defer func () {ifERR: = Recover (); Err! =Nil {//Handle our error.Fmt. Println ("FIX") fmt. Println ("ERR", Err)} }() //This causes an error.explode () fmt. Println ("reach here")//not up to}
Golang Recover panic Process Control for reach and unreachable