catch errors php
function inverse($x) {
if (!$x) {
throw new Exception('Division by zero.');
}
return 1/$x;
}Try catch comes under exception handeling concept where using this we control the runtime error and modify the message as we want.
// function created with exception throw
function checkdata($number){
if($number > 10){
throw new Exception("Number is greater than 10");
}
return true;
}
// try block starts
try{
checkdata(15);
echo "The number is below 10";
}
// catch block
catch(Exception $e){
echo "Message :".$e->getMessage();
}
In above code if condition is not satisfied then it will throw exception and which gets caught by catch block and show the error message.
Also in PHP:
- detect keyword of php string
- date_format timeformat php
- calcolo iva php
- clear date formatting php
- array merge in php
- create alphanumeric code php
- display folder contents php
- compare two arrays and return the difference php
- difference between two timestamps php
- current uri php[
- find a word in string in php
- convert to caps php
- add redirect php
- array_reverse in php
- change date format php
- creating web application with php and sparql on backend
- development wordpress plugin
- @foreach output reverse
- buscar palabra en un string php
- cache eloquent laravel 8
- alpha numeric to upper case in php
- convert date time to timestamp php
- HTML form, add the data into it and submit it to the database by connecting it to MySQL database using PHP.
- created_at date get in y-m-d H:i:s php