errors and excpetion 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:
- a.$t php
- datetime default format hour format ph
- check index type in php
- exceptions (throwing | catching) in php
- datetime format u
- check key in an array
- ?? ' ' operator in php laravel
- array reverse first level php
- check key exist in json php
- check for a key in array + php
- check is a value is on an string php
- character length in php
- date and hour php
- array_key does not exist php
- array_count_values php
- check method in laravel
- db seeder laravel 5
- accepts a, b, c, date and prints below the results together with the current date php
- How to fix undefined index: name in PackageManifest.php line 131 error with Composer
- Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in laravel of windows
- check if substring matches another string php
- create custom post type with category in wordpress functions.php
- execution time in php and how increase
- SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long