Skip to content

Instantly share code, notes, and snippets.

@artemrogov
Last active May 18, 2018 21:29
Show Gist options
  • Save artemrogov/da4351c42d1fc38ac0064d9b16c34c13 to your computer and use it in GitHub Desktop.
Save artemrogov/da4351c42d1fc38ac0064d9b16c34c13 to your computer and use it in GitHub Desktop.
Exception for php
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