Last active
May 18, 2018 21:29
-
-
Save artemrogov/da4351c42d1fc38ac0064d9b16c34c13 to your computer and use it in GitHub Desktop.
Exception for php
This file contains hidden or 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
function isNum($num){ | |
if ($num % 2 == 0){ | |
throw new Exception("Ты не верно решил пример!!"); | |
} | |
return $num; | |
} | |
try{ | |
echo isNum(4); | |
}catch (Exception $a){ | |
echo $a->getMessage(); | |
} | |
function dec($a){ | |
if ($a==0){ | |
throw new Exception('Переменная не должна быть равна нулю! Ошибка в строке: ',50); | |
} | |
return 0; | |
} | |
try { | |
echo dec(0); | |
}catch(Exception $e){ | |
echo $e->getMessage(); | |
echo $e->getCode(); | |
} | |
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++== | |
class GPS_Coord extends Exception{} | |
function drawPoint($point){ | |
if (is_string($point)){ | |
throw new GPS_Coord("Это строка!!"); | |
} | |
} | |
try { | |
drawPoint("dfdf"); | |
}catch(GPS_Coord $e){ | |
echo $e->getMessage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment