edrosten / libblepp

Modern clean C++ Bluetooth Low Energy on Linux without the Bluez DBUS API
Other
239 stars 62 forks source link

Catch polymorphic errors by reference #67

Closed heimskr closed 1 year ago

heimskr commented 1 year ago

Errors of polymorphic types (such as std::runtime_error) should be caught by reference to prevent object slicing (especially since what() is virtual). I'm not sure whether there's any possibility of subclasses of, say, std::runtime_error being thrown, but it doesn't hurt to catch by reference and at the very least this change silences some warnings.