You are viewing a single comment's thread. Return to all comments →
I think is better use invalid_argument or runtime_error. Nothing wrong to have your own class but code may be harder to read. For example I prefer
invalid_argument
runtime_error
if (n < 0 || p < 0) throw invalid_argument{"n and p should be non-negative"};
Instead of
if(num < 0 || pow < 0) throw neg_pow;
Code must be as more descritive as you can: writing throw invalid_argument{"n and p should be non-negative"}; is really more clear than throw neg_pow;
throw invalid_argument{"n and p should be non-negative"};
throw neg_pow;
Seems like cookies are disabled on this browser, please enable them to open this website
Day 17: More Exceptions
You are viewing a single comment's thread. Return to all comments →
I think is better use
invalid_argument
orruntime_error
. Nothing wrong to have your own class but code may be harder to read. For example I preferInstead of
Code must be as more descritive as you can: writing
throw invalid_argument{"n and p should be non-negative"};
is really more clear thanthrow neg_pow;