In current Go with the handle construct would look something like this:
handleerr{ifnotExist,ok:=err.(*os.ErrNotExist);ok{// Do stuff with notExist}elseifotherErr,ok:=err.(*pack.OtherErr);ok{// Do stuff with otherErr}}// Or if your list is very longhandleerr{switcherr.(type){case*os.ErrNotExist:// Code...case...:// ...default:// ...}}
Note that the notExist, ok := err.(*os.ErrNotExist) is how you typecast in Go. Also, a semicolon in an if statement means "just execute the left side normally and evaluate the right side as the condition", although any variables declared on the left side have block scope within the if statement.
Errors in Go are just an interface, so you just cast them to the error that you want to check.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
It would look something like this:
In current Go with the handle construct would look something like this:
Note that the
notExist, ok := err.(*os.ErrNotExist)
is how you typecast in Go. Also, a semicolon in an if statement means "just execute the left side normally and evaluate the right side as the condition", although any variables declared on the left side have block scope within the if statement.Errors in Go are just an interface, so you just cast them to the error that you want to check.