Add exams from exam156 to exam199
This commit is contained in:
12
exam185/throwEx.php
Normal file
12
exam185/throwEx.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
function divide($num1, $num2){
|
||||
if($num2 == 0){
|
||||
throw new Exception('Cannot devide by 0');
|
||||
} else {
|
||||
return $num1/$num2;
|
||||
}
|
||||
}
|
||||
|
||||
echo divide(10,0);
|
||||
?>
|
||||
17
exam185/trycatch.php
Normal file
17
exam185/trycatch.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
$age = 17;
|
||||
|
||||
try {
|
||||
|
||||
if ($age > 18){
|
||||
echo 'Old enough.';
|
||||
} else {
|
||||
throw new Exception('Not old enough');
|
||||
}
|
||||
} catch(Exception $ex){
|
||||
echo 'Error: '. $ex -> getMessage();
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user