by codedokode · 8y ago · 0 comments
I don't see the problem with that. Unhandled exceptions can occur at any place of your program.
I also don't see why the unhandled exception from the background thread cannot terminate main thread. Why not? That is how unhandled exceptions are supposed to work. Terminating the program is the optimal default behaviour for any error in my opinion. This way you won't miss them.
This is how unhandled promise rejections will be handled in node soon. In the browser, you can declare an event handler for unhandled promise rejections.
- return an error
- panic
What is the recommended, best, pretty, beautiful way? Return an error. Nobody uses panic.Javascript Promises are equivalent to that.
If you want to stop the main program, call process.exit(). That would be the equivalent of panic.
Chaining functions is for functional people. Go is proudly imperative.