#using custom error type definitions

12 messages · Page 1 of 1 (latest)

warm lantern
#

return NegativeSqtError(-3.14)

#

or return ConflictError{"user1234"}

leaden aurora
#

errors are just values, and error is just an interface. you can make a value of your error type like &ConflictError{Username: user.Username} and return it.

warm lantern
#

My bad, because the method receives a pointer type

#

func (e *ConflictError) Error() string { return "" }

#

Should revise methods and interfaces

#

Go tour has good pages on it

visual badger
#

@warm lantern Which go tour or effictive go pages do you recommend on this? I also have been interested in seeing what people do when handling many custom error types.

warm lantern
visual badger
#

@warm lantern I do like typing errors from previous experience working with C#, but the opaque practice seems very good. I just add helpers to check for things like isTransient, isTemporary, isValidation and such. Then at my domain layer I can add those checks to add the proper error message return types.

warm lantern
#

Yeah can also switch on the type