-
Notifications
You must be signed in to change notification settings - Fork 548
How ErrWrap works
xushiwei edited this page Jun 6, 2020
·
2 revisions
How do we convert ErrWrap expression?
var1, var2, ..., varN := foo()!
Will be converted into the following code:
_gop_1, _gop_2, ..., _gop_N, _gop_Np1 := foo()
if _gop_Np1 != nil {
panic(errors.NewFrame(_gop_Np1, ...))
}
var1, var2, ..., varN := _gop_1, _gop_2, ..., _gop_N
var1, var2, ..., varN := foo()?
Will be converted into the following code:
_gop_1, _gop_2, ..., _gop_N, _gop_Np1 := foo()
if _gop_Np1 != nil {
_ret_err = errors.NewFrame(_gop_Np1, ...)
return
}
var1, var2, ..., varN := _gop_1, _gop_2, ..., _gop_N
val := foo()?:defaultValue
Will be converted into the following code:
_gop_1, _gop_2 := foo()
if _gop_2 != nil {
_gop_1 = defaultValue
}
val := _gop_1