Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Especially since caught panics amount to exceptions and most Golang code isn't exception safe. It's a recipe for leaking database connections, deadlocks, etc.


Go error handling is awful, but this isn't a fair.

In go, if you write code like the following:

    conn, err := db.Connect()
    defer conn.Close()
That defer will be run during a panic. Same thing as 'defer mutex.Unlock()'

Yes, like most of go, it's manual and painful and poorly thought out, but most people do follow these patterns, so for the most part go code will safely unwind from a panic.


Most of the time, sure, but there are lots of cases where `defer` being function scoped leads to manual unlocks, e.g. inside loops or short critical sections in the middle of a function. Yes, you can use closures/otherwise, but few codebases are that disciplined. Those edge cases are plentiful enough that catching panics is dangerous.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: