Comment

Comment by laumars

Panics can be caught and handled by parent callers and thus behave a little bit like exceptions (not as pretty I'll grant you, but still better than the "no way out other than aborting the process" approach it seems at first glance). However you generally you don't want to catch panics except under rare conditions because panics are intended to be used in "the world is ending" kind of scenarios (it doesn't always work out this way but that is the theory).

For general error handling there is an error object that gets returned by functions. It leads to the often moaned about syntax below:

    if err != nil {
        return err
    }
Yeah it's ugly. Yeah other languages have try / etc. But for all of it's sins I've found it still gets the job done.
parent laumars 9 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton