Why Go Doesn't Have try/catch and What to Use Instead

Go omits try/catch to enforce explicit error checking via return values and if statements.

Go lacks try/catch to enforce explicit error handling, requiring you to check error return values directly instead of relying on automatic stack unwinding. You handle errors by assigning the second return value to a variable and using an if statement to check for nil.

r, err := zip.OpenReader("archive.zip")
if err != nil {
    return err
}
defer r.Close()