exception handling php databse
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:
- WooCommerce Add Long Description to Products on Shop Page with Character limit
- array filter only folder in php
- afficher type et contenu d'une variable php
- webp image validation in laravel
- $dbh = new PDO("mysql:host
- date('N') php
- check the value type in php
- check php variable type
- acf auto increment field
- array reverse in php example
- composer require guzzlehttp/guzzle
- doument root phpp
- ->with('success','msj')
- clear cash in laravel
- exceptions php
- add google analytics to website laravel
- all error in php
- date('Y ', $date);
- datetime form of date in php
- date format php string
- 3d array search
- date format in php function
- check if page is front page in wordpress
- extract contact page url php