fpagliughi / sockpp

Modern C++ socket library.
BSD 3-Clause "New" or "Revised" License
769 stars 126 forks source link

Make exceptions optional #72

Closed JakeSays closed 1 year ago

JakeSays commented 1 year ago

It would be great if this library could be used without exceptions. There are many environments where exceptions are not allowed.

fpagliughi commented 1 year ago

Ironically, this library fell out of a bigger framework for embedded systems that specifically did not use exceptions or runtime type identification. Somehow, though, over the years, exceptions made their way into it.

I count only a handful in the whole library, so it wouldn't be a crazy amount of work. But how should we handle:

  1. Constructors that detect errors
  2. Functions that just return a success value (and throw on error)
ldgeng commented 1 year ago

Ironically, this library fell out of a bigger framework for embedded systems that specifically did not use exceptions or runtime type identification. Somehow, though, over the years, exceptions made their way into it.

I count only a handful in the whole library, so it wouldn't be a crazy amount of work. But how should we handle:

  1. Constructors that detect errors
  2. Functions that just return a success value (and throw on error)

std::error_code?

ldgeng commented 1 year ago

just like winapi

fpagliughi commented 1 year ago

std::error_code?

Wowwwww... I had no idea that was even in there!. I'll definitely have a look at that. Thanks, @ldgeng.

fpagliughi commented 1 year ago

just like winapi

@ldgeng Can you point me to the winapi code that uses std::error_code?

fpagliughi commented 1 year ago

Moving to std::error_code would actually help with existing problems of platform error checks, and preset a road forward for TLS library error reporting. It also ties together a few other ideas. I am going to close this and move the conversation to Issue #77.

Please do comment on the ideas presented there. But, basically, it says "yes" to both of these ideas:

JakeSays commented 1 year ago

@fpagliughi hey this is perfect!