error handeling oops php
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:
- base64decode php
- Best debugging tools for php
- HOW TO FIND TYPE OF VARIABLE PHP
- codeigniter db insert return id
- capital letter php
- creating default object from empty value laravel
- carbon add minutes
- contains in string php
- create folder php
- Chace Clear of Larvel
- check if key exist in php
- create random unique password with php
- check if string contains substring at the start php
- doesn't appear favicon php
- date formate with pc time in php
- convert time string to timestamp php
- ?? ' ' operator in php laravel
- dot after each character php
- disallow search engines
- check composer using php version
- CODEIGNITER codeigniter 4 auth
- cambiare pagina php
- create model, controller and migration in single command laravel
- "Allowed memory size of 1073741824 bytes exhausted (tried to allocate 401952768 bytes)"