catch exception in 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:
- check index of string php
- default seed installation laravel
- PS C:\xampp\htdocs\recruit2> php artisan make:seeder Interviews Seeder Seeder already exists!
- !is_null in laravel
- create new laravel project 8
- fetch email from url contact form 7
- csv to json php
- can i install php7.4 inside vagrant homestead
- SOHW error details on php
- $headder in php
- android studio clear cache
- Fatal error: Allowed memory size of 1073741824 bytes exhausted (trie
- disable timestamps laravel
- <?phpheader("Location:
- apt-get install php 7.4
- artisan show routes
- apt install php7.4-mysql
- SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767
- add errors php
- check if word include string
- date"h" php
- convert all to uppercase php
- convert a image to base64 data in php and show image
- echo console log