Why does your program panic so much ? It sounds like if you solved all these panics you wouldn't need to invent a mechanism to recover from them.Panics are neither common place nor expected in Java, if your software is causing runtime panics you should address that root cause.
On Wednesday, 5 March 2014 11:34:23 UTC+11, ericce...@gmail.com wrote:So, I have a network server. Each connection is handled in a goroutine, which may spawn many other goroutines.Any of these goroutines might panic, so I need to put recover calls all over the place. If I miss one, that goroutine panicking will lead to the entire program crashing.So the simplest demonstration would be goroutine A spawning goroutine B, which panicks. Can I somehow catch the panic with code in A?The thing is that all the state my program keeps is connection-local basically, and I want a goroutine panic to kill the goroutines of one connection, instead of the whole program. This is feasible if each connection only has one goroutine (using recover), but not if there are multiple goroutines doing things in the background for one connection.Thanks!
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/Bi43JRE-c6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
I do think it could be useful to have something like runtime.PanicCallback which would register a func(interface{}) that would be called with the panic info. I'd make the definition something like "if a panic reaches the top of any goroutine stack (and is not recovered from), the global panic callback is called if registered. Before the callback is called, the rest of the world is stopped and the thread is locked. No goroutines may be spawned from the panic callback, nor may you read from or write to a channel, nor will any garbage be collected. After the function returns (or panics again), the stack trace will be printed as normal and the program will exit. You cannot recover in the panic callback."I think it could be very useful for scenarios with large numbers of different-acting Goroutines where you just want to do One Thing (save any program state you can verify sane, write a log file, display an error message in a new window, scream and cry) before your program dies from a stupid divide by zero error that only happens if you seed your RNG on the third Friday in August or something.
--
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.
--
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/Bi43JRE-c6w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
The thing is, using returning errors for these things leads to code repeat, since after every operation I need to check whether the connection closed suddenly, etc. If I even forget it at one single place, a protocol violation can silently put my program into an undefined state.
Wouldn't that be somewhat expensive? I know goroutines are super cheap, but, still, all those implicit locking around channels, constructing structures to pass around in channels, etc? IDK though, I might try that approach.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.