Skip to main content
Code Review

Return to Answer

replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
Source Link
  1. 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?

  1. 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.

  1. 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.

  1. 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?

  1. 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.

  1. 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.

  1. 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?

  1. 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.

  1. 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.

Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
  1. 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?

  1. 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.

  1. 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.

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /