FAQ
I agree with Paul, that they are fine to use in certain situation, but
certainly not in all situations. And most certainly, the panic should
never cross the package boundary.

However, I do feel like there are conflicting opinions on this. Dave
Cheney, can you clarify if your position on this? Are you saying that it is
never idiomatic to use panics? Or are there certain rare scenarios where it
is acceptable to use?

Interestingly, the Go proverbs mentions "don't panic" as the last proverb,
but in the video linked at the bottom, Rob Pike ends his talk after
"documentation is for the users", so I'm not exactly sure where that
proverb came from.

Also, the Defer, Panic, and Recover blog post
<http://blog.golang.org/defer-panic-and-recover> explicitly mentions
encoding/json as a real-world example of panic/recover. This seems to
indicate that it is fine to use panics in these situations.

JT
On Tuesday, January 12, 2016 at 7:34:56 AM UTC-8, Paul Borman wrote:

Go does support exceptions. That is exactly what panic/recover is, but it
is meant to be painful so you don't use them like they are used in other
languages.

That said, this mechanism should only be used internally to a package,
never as a mechanism to return an error outside the package. It should not
normally be needed, but at least for various parsing/translation paradigms
is it results in much cleaner and more readable code. When the right tool
is one you normally do not use, it does not mean it isn't the right tool
(but perhaps you should think twice).

-Paul

On Mon, Jan 11, 2016 at 10:20 PM, Dave Cheney <da...@cheney.net
<javascript:>> wrote:
This sounds like playing with fire for the convenience of maintaining an
illusion that Go supports an exception based control flow mechanism. It
really doesn't, your code will be considered more idiomatic if your use
return values for error handling.

Thanks

Dave

--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to golang-nuts...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 7 of 12 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 10, '16 at 12:25a
activeJan 12, '16 at 9:56p
posts12
users9
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase