How to transfer control to a specific line of code by raising error ? Following is the example scenario
https://play.golang.org/p/Ibdy0qibeNJ
package main
import (
"errors"
"fmt"
)
func doSomething() {
fmt.Println("Doing Something")
}
func doRun() {
fmt.Println("Doing Running")
}
func doPlay() {
fmt.Println("Doing Playing")
}
func doEat() {
fmt.Println("Doing Eating")
doEatNoodles()
//create an error
e: = errors.New("Too Lazy!! Donot want to execute the rest of the code..take me back to the end of
the flow please!!")
ErrorFound(e)
doEatBread()
}
func doEatNoodles() {
fmt.Println("Doing noodles eating")
}
func doEatBread() {
fmt.Println("Doing Bread eating")
}
func ErrorFound(err error) {
if err != nil {
//How should I throw an error here so that the flow gets stopped and doPlay() is not called
instead the control print
}
}
func main() {
//the goal is that if there is an error then the control should stop executing the flow and should go to t
the last line saying the flow ends here
fmt.Println("Flow Starts Here")
//the flow starts here
doSomething()
doRun()
doEat()
doPlay()
//the flow ends here
fmt.Println("Flow Ends Here")
}