fpagliughi / sockpp

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

sys_error improperly declared; not caught as std::exception #18

Closed snej closed 5 years ago

snej commented 5 years ago

One of my tests keeps crashing with uncaught exception of type sockpp::sys_error. The exception is expected (the test tries to connect to a nonexistent hostname) but my catch(const std::exception &x) { ... } is being ignored.

I finally realized the problem: sys_error is not compatible with type std::exception because it doesn't publicly inherit from it. Its declaration needs to be changed to

class sys_error : public std::runtime_error

i.e. adding public after the colon.

With this fix, my test works as expected.

fpagliughi commented 5 years ago

Yes mistake/bug on my part. Fixed by PR #20