Exception handling for 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:
- error reporting panvil.works
- PHP Fatal error: Composer detected issues in your platform: Your Composer depen dencies require a PHP version ">= 7.3.0". You are running 7.2.34.
- catch (exception $e) php
- Exception in php import
- filter_var filter_validate_url
- create random password with refresh in php
- customizing php time format based on location usa europe
- array to string separated by comma php
- date () php day and hour
- composer create project laravel 7
- acf options page
- check if string has substring php
- Allowed memory size of 67108864 bytes exhausted (tried to allocate 18878464 bytes) cpanel
- create project in laravel
- check if value in string php
- change php format time
- date( d ) in php
- check type of in php
- Create a cron job php
- display errors on
- array exists in php
- What happens when lava flow reaches the ocean?
- file to base64
- check my composer version