Go code
number, err := strconv.Atoi("no")
if err != nil {
fmt.Println("Invalid number")
return
}
fmt.Println(number)Line-by-line explanation
- Atoi cannot convert no.
- The if detects a non-nil error.
- A helpful message is displayed.
- Return stops the current function.
Expected output
Invalid numberThis is the expected result.