File tree Expand file tree Collapse file tree 2 files changed +4
-0
lines changed
Expand file tree Collapse file tree 2 files changed +4
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ namespace RubberNumbers {
1111 * @brief Represents the error caused by trying to divide by 0.
1212 */
1313class RubberDivisionByZero : public std ::runtime_error {
14+ public:
1415 /* *
1516 * @brief Creates a new DivisionByZero error object.
1617 */
Original file line number Diff line number Diff line change @@ -267,6 +267,9 @@ RubberNumbers::RubberInt& RubberNumbers::RubberInt::operator*=(const RubberInt&
267267
268268RubberNumbers::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;
You can’t perform that action at this time.
0 commit comments