catch php errors
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:
- Laravel Mix npm run production error
- $val & 4 in php
- convert unix timestamp to datetime php twig
- class 'illuminate support facades input' not found laravel 7
- back route laravel
- find if a string contain any of a given words php
- array key search php
- array_values() in php
- What was the old name of PHP?
- check array with name exists php
- Laravel DB facade relations
- detecting right click on windows
- Format Month as a number php
- check if page is front page in wordpress
- calling a php function in a catch block
- exception is thrown php
- email in ctf
- create new file in folder php
- check if array key exists in array php
- echo in json format php
- THROW EXPECTION PHP
- apache 2 lib php 7.4
- add one day in php
- find string into string