exceptional handling 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:
- data format php
- errpr reporting in php
- disadvantages of php
- Where are WordPress Pages and Posts Stored
- 404 page in laravel
- dropzone uploader php
- Allowed memory size of 1610612736 b
- check if number doesn't divide exactly by 3 php
- codeigniter where order by
- check if string contain word
- clear cache without using composer in laravel 8
- composer require guzzlehttp/guzzle
- array unique in laravel
- #2 - One To Many relationship - hasMany() - Laravel Eloquent Relationships
- creating seed file laravel
- db::statement in laravel
- created at time to number php
- check strinh in php
- does canada have a monarchy
- find index of occurrence php
- Target class [Barryvdh\Cors\HandleCors] does not exist.
- convert string to timestamp php
- array reverse order php
- create symfony project