Created
July 30, 2020 13:05
-
-
Save maxwellgithinji/aed25cf360ac7afdc4deac18d0020b9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"errors" | |
"fmt" | |
"log" | |
"os" | |
) | |
func main() { | |
f, err := os.Open("rumi.txt") | |
if errors.Is(err, os.ErrPermission) { | |
err = fmt.Errorf("you do not have permission to open the file: %w", err) | |
log.Println(err) | |
} else if errors.Is(err, os.ErrNotExist) { | |
err = fmt.Errorf("the file does not exist: %w", err) | |
log.Println(err) | |
} else if err != nil { | |
err = fmt.Errorf("file couldn't be opened: %w", err) | |
log.Println(err) | |
} | |
/* | |
if err == os.ErrPermission { | |
err = fmt.Errorf("you do not have permission to open the file: %w", err) | |
log.Println(err) | |
} else if err == os.ErrNotExist { | |
err = fmt.Errorf("the file does not exist: %w", err) | |
log.Println(err) | |
} else if err != nil { | |
// panic(err) | |
err = fmt.Errorf("file couldn't be opened: %w", err) | |
log.Println(err) | |
} | |
*/ | |
defer f.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment