Skip to content

Instantly share code, notes, and snippets.

@iamtchelo
Created December 5, 2013 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamtchelo/7798610 to your computer and use it in GitHub Desktop.
Save iamtchelo/7798610 to your computer and use it in GitHub Desktop.
<?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