Ah yes, that's a nice way -- thanks.

Still has the issue that it's fairly easy to forget ... oh well.

-Ben

On Monday, December 3, 2018 at 7:17:21 PM UTC-5, Jesse Rittner wrote:
>
> In this situation, we normally use named return variables. That way we can 
> just check if we are returning with an error in the defer.
>
> func DoTwoThings() (retErr error) {
>     tx, err := db.Begin()
>     if err != nil {
>         return err
>     }
>     defer func() {
>         if retErr != nil {
>             tx.Rollback()
>         }
>     }()
>
>     ...
> }
>
> Note that this doesn't account for panics.
>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to