Created
May 19, 2018 14:22
-
-
Save artemrogov/f2ff2c4acc57fa1b3ffc4a7b47470213 to your computer and use it in GitHub Desktop.
simple example for exception
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
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