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

Go does indeed has an exception handling system like most other languages. Errors and exceptions are very different things, though.

Of course, nothing stops you from building your own file handing package that overloads exception handlers to deal with errors. If it gains traction then it would prove the stdlib should consider a v2 API.

But that you already haven’t done so is telling…



You mean panics? They don't work across go routines so they're limited and hardly exception handling like most other languages


Which languages see exception handlers work across go routines?

Anyway, most don't. There is no difference from exception handlers in most other languages.

The syntax is a little different. Is that where you've become confused?


Languages in which try/catch/throw work across coroutine boundaries: Java, Javascript, and it's a standard feature in C++ coroutine libraries (and completely supported by the core C++ coroutine engine). So in my limited personal experience, among the languages that I am familiar with ... all of them except go.

Are there actually ANY languages other than go that have coroutines, and try/catch/throw mechanisms, where you cannot throw across a coroutine boundary?

And why would exception handlers NOT work across coroutine boundaries, other than laziness on the part of implementers?


> Languages in which try/catch/throw work across coroutine boundaries

You wha...? The question was about goroutines, not coroutines.

Besides, you'll notice that exception handlers cross coroutine boundaries in Go just fine. Your random tangent isn't even correct. Where did you dream up this idea to the contrary? I know coroutines are still new to Go, only officially landing in the latest release (experimentally in 1.22), but you'd think that would also mean their behaviour is fresh in your memory.

I'll take your avoidance of the original question to mean that no other language does it either.


I answered as I did because the original question seems strangely broken. The premise upon which the question is asked is flawed.

What are goroutines, other than peculiarly broken coroutines? (Notwithstanding your point that go has a non-broken implementation of coroutines at experimental release stage).

It is true that Javascript has a goroutine-like facility for executing coroutines on a seperate thread. But there are languages (c++, c# at least) where coroutines can execute on separate threads without suffering from the broken-ness of goroutines.


There's a self-selection problem though. People who prefer error handling through exceptions are just not going to use go. Period. Will not use it. Been there done that. No no no.

So it is telling. But I think what it actually tells is that people would have done it just use another language instead.


Most of the other options don't include native code compilation though. I suppose Swift is there but doesn't make much sense outside of the Apple ecosystem.


As they should. Scripting tasks are, indeed, best performed in scripting languages.


"You can always make your own" is missing the point. Of course it's useless if a single library implements error handling differently than the rest of the language. The question is why the language does have this kind of manual error handling as a standard in the first kind.

> If it gains traction then it would prove the stdlib should consider a v2 API.

Some library that behaves completely differently from the rest of the language and breaks all interop with the rest of the ecosystem will have a hard time gaining traction, no matter if the way the library does it is objectively better or not.


> The question is why the language does have this kind of manual error handling as a standard in the first kind.

Probably for the same reason Rust does, and why it suffers much the same problem:

1. It is what was in vogue in the 2010s.

2. More importantly, the problem isn't limited to errors. What have you gained treating errors as some hyper special case when they aren't any different than any other value?

I think we agree that we can do better, but seeing errors as special doesn't get you there. We need something that understands the all-encompassing problem.

So, failing that understanding, if you're going to do something that sucks, you may as well choose the least-sucky option, surely? Exception handling brings a horrible developer experience. To the point that in languages where errors over exception handling semantics are the norm, you will find that most developers simply give up on error handling entirely because it is so painful.

> Some library that behaves completely differently from the rest of the language and breaks all interop with the rest of the ecosystem will have a hard time gaining traction

I'm not sure history agrees. Ruby was also of the return values over exception handling mind before Rails came along. Rails pushed exception handlers for errors and developers went for it. Provide an API people actually want to use, and they'll use it. What was common before is inconsequential.

I expect what you are really saying is that exception handling wouldn't actually improve this example case even in the best case, and in the worst case developers would end up giving up on error handling leaving such a package to be a net negative to a codebase.




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

Search: