On Tue, 23 Feb 2021 at 12:10, Kevin Chadwick <m8il1i...@gmail.com> wrote:
> I only instigate panic manually for one thing. Perhaps that will change, > but I doubt it. > > If I want to send out or write a log to disk then I will call panic rather > than os.exit, upon a log.fatal scenario. Think buffered go routine logging. > Saving the coder from having to think about it, once initialised. > > Which produces some ugly output and likely extra processing. > > Is it possible to call panic in a way that does not kill the process like > os.Exit, but without log pollution? > > I am solely thinking of manually instigated panics, so a noop panic called > something like terminate? > > Or is this bad practice, even when a program is in good operational order > when instigated, as the OS is better at cleanup? > Personally, I'd advise against using panic or log.Fatal in this kind of context - I'd just bite the bullet and return errors instead. This makes it easy to move code between contexts if you need to without worrying about non-local control flow. For unexpected panics, you can still use recover to flush your log buffers, assuming the panic happens in code that's been called by your code. cheers, rog. > > -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/3A8FA632-4991-4245-ABB3-8F4CE1164703%40gmail.com > . > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAJhgacg0q31bn5K9SeyUmW%2BKjEg-d31xov095ixAn9Zs9VShEg%40mail.gmail.com.