Skip to content

Commit

Permalink
WIP: exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
uestla committed Mar 19, 2023
1 parent 3b301c1 commit 0772e67
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Simplex/Fraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function getDenominator()
public function canonicalize()
{
if ($this->d === '0') {
throw new \Exception('Division by zero.');
throw new DivisionByZeroException('Division by zero.');
}

$gcd = Helpers::gcd($this->n, $this->d);
Expand Down
16 changes: 16 additions & 0 deletions Simplex/exceptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/**
* This file is part of the SimplexCalculator library
*
* Copyright (c) 2014 Petr Kessler (https://kesspess.cz)
*
* @license MIT
* @link https://github.com/uestla/Simplex-Calculator
*/

namespace Simplex;


final class DivisionByZeroException extends \Exception
{}
1 change: 1 addition & 0 deletions Simplex/simplex.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

require_once __DIR__ . '/exceptions.php';
require_once __DIR__ . '/Math.php';
require_once __DIR__ . '/Helpers.php';
require_once __DIR__ . '/Fraction.php';
Expand Down
2 changes: 1 addition & 1 deletion tests/FractionTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class FractionTest extends TestCase
Assert::exception(function () {
new Fraction(3, 0);

}, 'Exception', 'Division by zero.');
}, 'Simplex\\DivisionByZeroException', 'Division by zero.');
}


Expand Down

0 comments on commit 0772e67

Please sign in to comment.