catching error 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:
- array_key_exists contains string
- $join is_array() in code
- check if value contain letter php
- Cache::forget laravel command
- check type of php
- check if a word is present inside a string in php
- apache php e_warnings e_notice off
- count the no of characters in a string in phph
- create database backup programmatically php
- Route [login] not defined.Route [login] not defined.
- eloquent all only one culomn
- codeigniter id of last insert
- create new laravel project composer
- file to base64
- date format php l with capital
- assoc key unique php
- error enable in php
- check type of object in php
- add 1 month to date php
- Str in laravel
- can i throw exception in catch block php
- adding spasifc date to date('Y-m-d H:i:s') php
- create random unique string
- artisan clear cache command