more idiomatic way to throw & catch parse errors #9

Merged
MtnViewJohn merged 1 commit from packaging into master 2024-11-08 21:40:55 +01:00
MtnViewJohn commented 2024-11-08 06:50:40 +01:00 (Migrated from github.com)

It is much better to inherit from std::runtime_exception than std::string. std::string, with its non-virtual destructor, is not meant to be a base class. std::runtime_exception is designed to be a base class and contains a std::string.

It is much better to inherit from std::runtime_exception than std::string. std::string, with its non-virtual destructor, is not meant to be a base class. std::runtime_exception is designed to be a base class and contains a std::string.
MtnViewJohn commented 2024-11-08 17:55:56 +01:00 (Migrated from github.com)

Another reason for Parse to inherit from std::runtime_exception instead of std::string is that copying a std::string can throw an exception while copying a std::runtime_exception cannot. Thrown objects should be no-throw copyable. The what-string in std::runtime_exception is const and ref-counted, it is not duplicated on copy.

Another reason for Parse to inherit from std::runtime_exception instead of std::string is that copying a std::string can throw an exception while copying a std::runtime_exception cannot. Thrown objects should be no-throw copyable. The what-string in std::runtime_exception is const and ref-counted, it is not duplicated on copy.
Sign in to join this conversation.
No description provided.