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. try
{
// Some code...
}
catch(AError | BError $e)
{
// Handle exceptions
}
catch(Exception $e)
{
// Handle the general case
}
Also in PHP:
- New York Yankees
- date add days php
- array value exists php
- date +1
- find index of occurrence php
- Library not loaded: /usr/local/opt/icu4c/lib/libicuio.64.dylib Referenced from: /usr/local/bin/php
- SQLSTATE[42S02] lumen
- confirm before submit form php
- codeigniter get last insert
- display data from two dimensional array in vew laravel
- database seeder laravel 8.x
- check duplicate data in array php
- create new authentication middleware laravel
- Search or Filter Data in GridView c#
- ? for types in php
- Allowed memory size of 1610612736 bytes exhausted xampp
- Method Illuminate\Database\Eloquent\Collection
- a.$t php
- compare string length php
- catch (exception $e) php
- array exists in php
- completely clening cache laravele mysql
- code seef laravel
- display errors in production