Concept

How do you catch exceptions in PHP?

ComputerScienceOne / Catching Exceptions

"To catch an exception in PHP you can use the standard try-catch control block. Optionally (and as of PHP version 5.5.0) you can use the finally block to clean up any resources or execute code regardless of whether or not an exception was raised. Consider the simple task of reading input from a user and manually parsing its value into an integer. If the user enters a non-numeric value, parsing will fail and we should instead throw an exception. Consider the following function.\n\n1 function readNumber() {\n\n2 $input = readline(\"Please enter a number: \");\n\n3 if( is_numeric($input) ) {\n\n4 $value = floatval($input);\n\n5 } else {\n\n6 throw new Exception(\"Invalid input!\");\n\n7 }\n\n8 }"

Related Ideas

How do you catch exceptions in PHP? | ComputerScienceOne | Bifalgorithm | Bifalgorithm