# Go Error Handling Basics
###### tags: `golang`
[TOC]
# Nil Value
Means a value has not been initialized.
**Other Languages:**
>Javascript > null
>Java > null
>Swift > nil
>Python > None
>Ruby > nil[color=orange]
# Error Value
Go does not have **try catch statements or exceptions** like other languages.
***Let's take these functions as example:***
* func Itoa(i int) string -> never has errors b/c any int can converted into string
* func Atoi(s string) (int, error) -> this one returns an error type, if string cannot be converted into int.
**Note:**
In **Atoi function** error will be nil if it success, otherwise it would be a non-nil one. This method will fail if input a wording or even a float number.
**Success Example:**
```go=
i, err := strconv.Atoi("8")
fmt.Println("Converted N: ", i)
fmt.Println("Returned Err: ", err)
//Printed Answer
// Converted N: 8
// Returned Err: <nil>
```
**Fail Example:**
```go=
i, err := strconv.Atoi("hello")
fmt.Println("Converted N: ", i)
fmt.Println("Returned Err: ", err)
//Printed Answer
// Converted N: 0
// Returned Err: strconv.Atoi: parsing "hello": invalid syntax
```
As we can see, if there is an error, the int will just automatically become 0 and error will not be nil.
# How to handle Errors in GO?
In Golang we would just check whether the error is nil or not, to see whether there is any error.
**Note:** Atoi converts **String Value to Int value**.
```go=
if len(os.Args) > 1 {
printValue()
} else {
fmt.Println("No value given!")
}
// =========
func printValue() {
input := os.Args[1]
i, err := strconv.Atoi(input)
if err != nil {
fmt.Println("It Failed!")
fmt.Println("Returned Err: ", err)
return
}
fmt.Println("Converted N: ", i)
}
```