Choose Category
package main import ( "errors" "fmt" ) func main() { var car = Car{} car.name = "Audi" var _, error = car.getMileage() var customException *CustomException if errors.As(error, &customException) { fmt.Printf("in custom exception %s %+v", customException.customMessage, error) } else { println("in generic exception") } } type CustomException struct { customMessage string } func (customException CustomException) Error() string { return "CustomException" } type Car struct { name string } func (car Car) getMileage() (int, error) { var myException = CustomException{} myException.customMessage = "Omg" return -1, &myException }