These specific exception types help you communicate exactly what went wrong. out_of_range: thrown when an index or key is outside valid bounds. vector::at() throws this. throw out_of_range("Index must be 0-99"); invalid_argument: thrown when a function receives an inappropriate value.
throw invalid_argument("Size cannot be negative"); Using specific types lets callers catch and handle specific errors: catch (const out_of_range& e) might prompt for a new index, while invalid_argument might show usage help.