calling a php function in a catch block
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. try
{
// Some code...
}
catch(AError | BError $e)
{
// Handle exceptions
}
catch(Exception $e)
{
// Handle the general case
}
Also in PHP:
- after validate credential header is not redirect to another page in php in live server
- combine date time php
- create project larave
- current date time in php
- How to add validation form image in laravel
- Throw new error php
- create table and insert data in wordpress plugin
- Tests\Feature\BlogTest > user can delete post 162 Illuminate\Encryption\MissingAppKeyException No application encryption key has been specified.
- cache clear in code php laravel
- create migration, controller, model and seeder laravel
- date weschools
- calculate string length php
- clean laravel
- date method in php
- $s->$h php code
- does php reverse array function
- PHP if exists string
- check array with name exists php
- add days to date in php
- check if word in string
- create controller in laravel command line
- Allowed memory size of 1610612736 bytes exhausted larave lvalet composer
- clear all cache laravel server
- PHP Startup: Unable to load dynamic library 'curl'