3 ms·
Isn't that the same if you make a completely synchronous library without any goroutine? If your library panics then the whole program crashes.
by VonGallifrey 3y ago
Isn't that the same if you make a completely synchronous library without any goroutine? If your library panics then the whole program crashes.
- skybrian 3y agoIt's not the same because for any single goroutine, you can catch the panic at top level. But it only works if you wrote the top-level code for each goroutine. (For a completely synchronous program, you wrote the main function.) If all the work is done with one function call, it might be pretty similar to a program crash, except that you can log or restart in main, and you could use it as part of a larger program that does other stuff too.
- Too 3y agoFrom what I understand, Go code is usually written with the assumption that panics are fatal, not recoverable as exceptions. Trying to recover from them, as though they were exceptions, will expose other bugs, like functions not using defer to do cleanup, releasing mutex and such.