Skip to content

Commit 2f75c8b

Browse files
committed
Casting Uint to uintmax_t now throws range_error not overflow_error
This is for thinking ahead when we will have signed types and we want to have a uniform excpetion API Underflow exception is used for operations between Uints, range_error will be used when converting to uintmax_t or intmax_t and the value is too big or too small for the result type
1 parent 26cd7a0 commit 2f75c8b

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ else()
99
set(ARBY_SUBPROJECT ON)
1010
endif()
1111

12-
project(arby VERSION 0.1.0 LANGUAGES CXX)
12+
project(arby VERSION 0.2.0 LANGUAGES CXX)
1313

1414
find_program(CCACHE_PROGRAM ccache)
1515
if(CCACHE_PROGRAM)

arby/include/arby/arby.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ namespace com::saxbophone::arby {
181181
Uint(std::string digits);
182182
/**
183183
* @returns Value of this Uint object cast to uintmax_t
184-
* @throws std::overflow_error when Uint value is out of range for
184+
* @throws std::range_error when Uint value is out of range for
185185
* uintmax_t
186186
*/
187187
explicit constexprvector operator uintmax_t() const {
188188
// prevent overflow of uintmax_t
189189
if (*this > std::numeric_limits<uintmax_t>::max()) {
190-
throw std::overflow_error("value too large for uintmax_t");
190+
throw std::range_error("value too large for uintmax_t");
191191
}
192192
uintmax_t accumulator = 0;
193193
uintmax_t current_radix = 1;

tests/casting.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ TEST_CASE("Casting arby::Uint to uintmax_t", "[casting]") {
1313
CHECK((uintmax_t)arby::Uint(value) == value);
1414
}
1515

16-
TEST_CASE("Casting arby::Uint with value higher than UINT_MAX to uintmax_t throws overflow_error", "[casting]") {
16+
TEST_CASE("Casting arby::Uint with value higher than UINT_MAX to uintmax_t throws range_error", "[casting]") {
1717
arby::Uint value = arby::Uint(std::numeric_limits<uintmax_t>::max()) + 1;
1818

19-
CHECK_THROWS_AS((uintmax_t)value, std::overflow_error);
19+
CHECK_THROWS_AS((uintmax_t)value, std::range_error);
2020
}

0 commit comments

Comments
 (0)