Comment

Comment by ubershmekel

I agree that exceptions can be cumbersome at times. And I do prefer the Go parsing float example to the try/catch one if my entire program is only one line.

But in order to live in peace you have to either:

* Force every programmer to always check all the error values.

or

* Allow errors to pass silently.

So either you accept Go as a heavy-duty, heavy boilerplate error handling laden language. Or you accept it as a flaky, risky language.

Exceptions are the better compromise in my opinion. You get much cleaner code.

If this is the more common pattern for your programming life:

    try:
        f = float(someText)
        use_it_here(f)
        use_it_there(f)
    catch Exception:
        # I wanted to do things, but something went wrong.
        # Here's what to do now, this is easy
Then you're better off using exceptions. If you need to check every single call (e.g. NASA or Kernel programming) then you might prefer this:

    if f, err := strconv.ParseFloat(text); err != nil {
      // do something
    }
    if f, err := use_it_here(text); err != nil {
      // do something
    }
    if f, err := use_it_there(text); err != nil {
      // do something
    }
parent ubershmekel 14 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton