Skip to content

Commit 316eb5b

Browse files
committed
Fixed failing tests
1 parent e54a886 commit 316eb5b

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

include/RubberNumbers/RubberIntegers.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace RubberNumbers {
1111
* @brief Represents the error caused by trying to divide by 0.
1212
*/
1313
class RubberDivisionByZero : public std::runtime_error {
14+
public:
1415
/**
1516
* @brief Creates a new DivisionByZero error object.
1617
*/

src/RubberNumbers/RubberIntegers.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ RubberNumbers::RubberInt& RubberNumbers::RubberInt::operator*=(const RubberInt&
267267

268268
RubberNumbers::RubberInt RubberNumbers::RubberInt::operator/(const RubberInt& num2) const
269269
{
270+
if (num2.toString() == "0") {
271+
throw RubberDivisionByZero();
272+
}
270273
const RubberInt dividend = this->abs();
271274
const RubberInt divisor = num2.abs();
272275
RubberInt remainder;

0 commit comments

Comments
 (0)