Skip to content

Commit

Permalink
added naked return code
Browse files Browse the repository at this point in the history
  • Loading branch information
gandhi-jay committed Dec 2, 2017
1 parent 9ce84d1 commit f5bba9c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 13_go_functions/2_a_naked_return/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

func main() {

}

// Inside the if statement we are creating a new variable called err.
// We are not using the err variable declared as the function return argument.
// The compiler recognizes this and produces the error.
// If the compiler did not report this error,
// you would never see the error that occured inside the if statement.
// The return err variable is what is passed by default

// func returnID() (id int, err error) {
// id = 10

// if id == 10 {
// err := fmt.Errorf("Invalid Id\n")
// return
// }

// return
// }

0 comments on commit f5bba9c

Please sign in to comment.