Le 04/05/13 17:57, Anurag Kalia a écrit :
Just to be sure I'm not trying to solve an issue that doesn't needs to be solved: Given
date d = day(33) / month(5) / 2013;
Note that I has a typo on the day. This is equivalent on my implementation to
date d(year(2013), month(5), day(33));
If I want to throw a bad date exception I would need to check that the day/month and year are in range. Next follows the code:
days_date::days_date(year y, month m, day d) { if (set_if_valid_date(y, m, d)) return; throw bad_date("day " + to_string(d) + " is out of range for " + to_string(y) + '-' + to_string(m)); }
bool days_date::set_if_valid_date(year y, month m, day d) noexcept; I have a question here. Why are we not throwing the exception from set_if_valid_date() itself? Why did we include noexcept in its definition?
set_if_valid_date allows the user make changes without using exceptions. This is useful on some contexts. Best, Vicente