Re: [asio-users] asio and good error handling
Brought to you by:
chris_kohlhoff
From: Jeff A. <je...@p2...> - 2018-12-27 21:46:36
|
Thanks, but I think I must not have been clear. This code will run in production. Seeing in the logs what errors have occurred is important, and I do that. But just as important is for the binary to recover. If it got an error because someone with whom it communicates failed, it should just try again, but not too fast, to reconnect if it can. If it's a network issue, maybe it doesn't need to try to reconnect the socket, just understand that it timed out and to try to retransmit again. I have enough programs running that something will always be having an issue with something. But all the examples I've been finding are, well, examples: they don't provide much help understanding the set of recovery strategies for each of the errors I might receive. I've got enough of my own bugs to keep me going: I'd be very happy not to have to get this working by thinking through every last case. Jeff On 27/12/18 22:32, Dmitrij V wrote: > There are two ways to handle the errors. > > 1) exceptions: > > try { /* ... */ } > catch (const asio::error_code &ec) { > std::cerr << "error: " << ec.message() << std::endl; > } > > 2) and by place: > > error_code ec; > > asio::read(sock, buff, ec); > > if (ec) std::cerr << "error: " << ec.message() << std::endl; > > > If you want detailed error reporting - see class error_code (header > <asio/error_code.hpp>) > and its methods like: value(), category() ... > > PS: For me enough string by error_code::message() (for logs)... > > -- > the best regards > > > _______________________________________________ > asio-users mailing list > asi...@li... > https://lists.sourceforge.net/lists/listinfo/asio-users > _______________________________________________ > Using Asio? List your project at > http://think-async.com/Asio/WhoIsUsingAsio -- Jeff Abrahamson +33 6 24 40 01 57 +44 7920 594 255 https://www.p27.eu/jeff/ https://www.transport-nantes.com/ |