Knaph

Packages, Modules, and Testing61 of 62

Safe Divide with Recover

safeDivide panics on purpose when b is 0. Complete it by deferring a function that calls recover(); if it returns non-nil, set the named return value err to fmt.Errorf("recovered from panic: %v", r). main already handles printing the error or the result.

Sign in to try this exercise.