Skip to content

Instantly share code, notes, and snippets.

@artemrogov
Created May 19, 2018 14:22
Show Gist options
  • Save artemrogov/f2ff2c4acc57fa1b3ffc4a7b47470213 to your computer and use it in GitHub Desktop.
Save artemrogov/f2ff2c4acc57fa1b3ffc4a7b47470213 to your computer and use it in GitHub Desktop.
simple example for exception
class GPS_Coord extends Exception{}
class OutputCoord extends Exception {}
class ErorrNullable extends Exception{}
function drawPoint($point){
if ($point!=0){
if (is_string($point)){
throw new GPS_Coord("Это строка!!", 200);
}
elseif($point > 500 && $point<10){
throw new OutputCoord("point >500 Erorr input user!", 300);
}
else return $point;
}
else throw new ErorrNullable("Nullable number! Error",100);
}
try {
echo drawPoint(3);
}catch(GPS_Coord $e){
echo $e->getMessage();
}catch(OutputCoord $e){
echo $e->getMessage();
}catch(ErorrNullable $e){
echo $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment