exception handeling 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:
- customizing php time format based on location usa europe
- datetime in php
- check for character in string php
- check is home page
- artisan migrate single class
- execution time in php and how increase
- check if a string has a certain character php
- data type php get
- Does ,date('Y-m-d H:i:s') grab local pc or server pc time
- array exists in php
- Which of the following Laravel frameworks can be used to manage the dependencies of a PHP software?
- array_key_exists in laravel
- array_search in php
- blood groups laravel seeder
- clear cache route laravel
- eloquent timestamps false
- check string in php
- cache and compile file clear laravel
- character split php
- composer and php version
- Arr::pull()
- do_shortcode
- Your Composer dependencies require a PHP version ">= 7.2.5". You are running 7.2.0. in
- convert small to capital in php