catching errors 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:
- codeigniter get insert iditer print last query
- echo json php
- clear cache php artisan
- @ in php to supress error in php
- clear cach php artisan
- add new column in existing table in laravel migration
- Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) composer
- by default null eloquent user data in relationship in laravel 8
- add day php date
- Customer::insert([ 'customer_name' => $request->customer_name, 'customer_mobile'=> $request->customer_mobile, 'user_id'=>Auth::user()->id, 'created_at'=> Carbon::now() ]);
- date php W_z
- acf show the taxonomy image
- check which database connect laravel
- convert time format in php
- Eloquent Query Scope on Relationships
- artisan route list
- cron.php
- Laravel users_email_unique
- check session php
- all capital in php
- Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.3.0". You are running 7.2.33.
- add no of days to date php
- check if contains substring php
- add 1 day to date php