News for hackers. Stuff that matters.
Re:Quick and Clean in Go by zemo on Wednesday August 01, 2012 @05:06PM (#4325705)
>If you have 10 calls to ListenAndServe

ListenAndServe blocks forever. If you have 10 calls to ListenAndServe, it's implied that you're in 10 different, concurrently running processes (goroutines). A panic, in Go, does not cross a goroutine boundary. If, in imaginary parallel universe Go with exceptions, exceptions did cross goroutine boundaries, then one goroutine could crash another goroutine.

The point of Go is to be able to sensibly write stable, concurrent programs with compile-time safety. Exception-based error handling would be a mess with Go's concurrency model.

In practice, you would only call ListenAndServe 10 times if you were listening on 10 different ports, because you had 10 different projects on the same server. That's a perfectly realistic situation. Now consider that one site has an error and throws an exception. Should all the other sites go down?

Error handling in Go is admittedly tedious, but when you work with the language for a bit you'll start to understand why they chose to design it in that manner.

Re:Quick and Clean in Go by flogic on Wednesday August 01, 2012 @07:13PM (#4326287)
If Panic doesn't cross goroutine boundaries, why should exceptions?
Re:Quick and Clean in Go by drivebyacct2 on Wednesday August 01, 2012 @07:24PM (#4326338)
The whole point is, it wouldn't make sense for them to cross goroutine boundaries, but the pleasure of Go is the ease with which you can use goroutines. Thus, in a lot of places where people would lazily use exceptions to aggregate potential errors, you would be unable to because the exception is occuring in a goroutine.

Which is why there are other nice ways of communicating such states in go that go hand in hand with handling errors at their occurrence. If you find an error in a goroutine, you can signal that on a channel, return and wait for a new goroutine to be restarted in place of the errored one.