My code right now looks something like this:void throw_illegal_part_of_input_exception(char c) {}void throw_invalid_input_length_exception(int position, int length) {}void throw_invalid_subinput_length_exception(int position, int length, bool is_greater) {}// Some other similar functions// ... do some stuff inside a functionif (errorCondition1) {    throw_invalid_character_exception(c);} else if (errorCondition2) {    throw_invalid_input_length_exception(position, length);} // etceteraThe content of the functions is largely the same; however, the error messages I want to use in the thrown exceptions are very different and depend on the arguments. Is there a better way to write this?
What's the best way to handle slightly different exceptions?
code quality;refactoring;exceptions
There is no real best way. There are some options:Create an exception hierarchy with a class for each specific exception that all inherit from a common base class (the exception class you are using now for example). Each specific exception class then carries the details of the encountered error and can produce a human-readable message when the what() method gets called.This option is particularly useful if you might want to differentiate between the different exceptions in your catch clauses.Use a single exception type that gets filled with different messages at the throw point.This is your current approach and is perfectly valid if you know beforehand that the calling code will never have a need to differentiate between the different kinds of errors.If there is no need to have different exception types, then it comes down mostly to personal preference and agreements within the team which option to use. We can't advise in that.