4 ms·
How are errors in deferred functions handled? How about division by zero?
by sfk 12y ago
How are errors in deferred functions handled? How about division by zero?
- NateDad 12y agoerrors in deferred functions are handled just like they would be if the function were not deferred. There are some things like division by zero and array index out of bounds that cannot be used with this method without making the language incredibly cumbersome... for those, there are panics (basically like exceptions in other languages)... but they happen quite rarely in practice.
- Jayschwa 12y agoDeferred functions can pass along errors by using a closure. http://play.golang.org/p/_ZqSk470-b http://play.golang.org/p/_ZqSk470-b