Created
December 5, 2013 01:16
-
-
Save iamtchelo/7798610 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Math | |
{ | |
public function sum($a, $b) | |
{ | |
if (!is_numeric($a) || !is_numeric($b)) { | |
throw new InvalidArgumentException('Invalid Numbers'); | |
} | |
// sum | |
$result = $a + $b; | |
if ($result > 10) { | |
throw new OutOfRangeException('Result greater than 10'); | |
} | |
return $result; | |
} | |
} | |
$math = new Math(); | |
try { | |
echo $math->sum(10, 50); | |
} catch (InvalidArgumentException $e) { | |
echo 'There was an error in the calculate: ' . $e->getMessage(); | |
} catch (OutOfRangeException $e) { | |
echo 'There was an error during workflow: ' . $e->getMessage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment