История изменений
Исправление Deleted, (текущая версия) :
я вот таким образом реализую модель исключений и их отработки
var errorLLSNlist = map[int]string{
100: "blabla blablabla",
}
type ErrorLLSN struct {
code int
}
func (e *ErrorLLSN) Error() string {
return errorLLSNlist[e.code]
}
func (e *ErrorLLSN) Code() int {
return e.code
}
func oops(code int) {
panic(&ErrorLLSN{code})
}
////// how to recover and get the error code/description
defer func() {
if r := recover(); r != nil {
rrr := r.(*ErrorLLSN)
fmt.Printf("Recovered error: [code %d] %s \n", rrr.Code(), r)
}
}()
собственно в коде дергаешь oops с кодом ошибки, а рекавер делаешь как тебе по логике нужно.
Исходная версия Deleted, :
я вот таким образом реализую модель исключений и их отработки
var errorLLSNlist = map[int]string{
100: "blabla blablabla",
}
type ErrorLLSN struct {
code int
}
func (e *ErrorLLSN) Error() string {
return errorLLSNlist[e.code]
}
func (e *ErrorLLSN) Code() int {
return e.code
}
func oops(code int) {
panic(&ErrorLLSN{code})
}
////// how to recover and get the error code/description
defer func() {
if r := recover(); r != nil {
rrr := r.(*ErrorLLSN)
fmt.Printf("Recovered error: [code %d] %s \n", rrr.Code(), r)
}
}()