- I've been searching online for exception class design, and haven't found anything like this. This worries me. Is there something wrong with designing exceptions this way?
Here is my opinion: What is a 'good number' of exceptions to implement for my library What is a 'good number' of exceptions to implement for my library?
- Are there any considerations to think about when deriving from one of the standard exceptions? Or should I just derive from std::exception and not worry about?
You should probably derive from std::runtime_error
.
- One problem with this design is that the format of the string is dependent on this class. Is there any good way to decouple this?
Use the string in the exception solely for logging (not for generating a user error message). The exception will generally carry technical information that is not relevant to the user.
But when displaying information to the user you should generate a formatted string at the catch point (not the throw point). This is because you can not tell what the output device is going to be used at the throw point.
- I've been searching online for exception class design, and haven't found anything like this. This worries me. Is there something wrong with designing exceptions this way?
Here is my opinion: What is a 'good number' of exceptions to implement for my library?
- Are there any considerations to think about when deriving from one of the standard exceptions? Or should I just derive from std::exception and not worry about?
You should probably derive from std::runtime_error
.
- One problem with this design is that the format of the string is dependent on this class. Is there any good way to decouple this?
Use the string in the exception solely for logging (not for generating a user error message). The exception will generally carry technical information that is not relevant to the user.
But when displaying information to the user you should generate a formatted string at the catch point (not the throw point). This is because you can not tell what the output device is going to be used at the throw point.
- I've been searching online for exception class design, and haven't found anything like this. This worries me. Is there something wrong with designing exceptions this way?
Here is my opinion: What is a 'good number' of exceptions to implement for my library?
- Are there any considerations to think about when deriving from one of the standard exceptions? Or should I just derive from std::exception and not worry about?
You should probably derive from std::runtime_error
.
- One problem with this design is that the format of the string is dependent on this class. Is there any good way to decouple this?
Use the string in the exception solely for logging (not for generating a user error message). The exception will generally carry technical information that is not relevant to the user.
But when displaying information to the user you should generate a formatted string at the catch point (not the throw point). This is because you can not tell what the output device is going to be used at the throw point.
- I've been searching online for exception class design, and haven't found anything like this. This worries me. Is there something wrong with designing exceptions this way?
Here is my opinion: What is a 'good number' of exceptions to implement for my library?
- Are there any considerations to think about when deriving from one of the standard exceptions? Or should I just derive from std::exception and not worry about?
You should probably derive from std::runtime_error
.
- One problem with this design is that the format of the string is dependent on this class. Is there any good way to decouple this?
Use the string in the exception solely for logging (not for generating a user error message). The exception will generally carry technical information that is not relevant to the user.
But when displaying information to the user you should generate a formatted string at the catch point (not the throw point). This is because you can not tell what the output device is going to be used at the throw point.