excpetion handling php
function inverse($x) {
if (!$x) {
throw new Exception('Division by zero.');
}
return 1/$x;
}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:
- date('hms'
- date php français
- descargar laravel
- console value in php
- control string length php
- date from format php
- Type error: Argument 1 passed to Illuminate\Database\Grammar::parameterize()
- create directory by php
- db:seed not seeding to db laravel 8
- How to format date from datetime php
- console.log not working php
- capitalize letter in php
- <?php function webmull($webmull) { switch ($webmull) { case 'e': print('5'); break; case 'm': echo('6'); break; case 'b': continue; break; default: echo '7'; break; } } webmull('w'); webmull('e'); webmull('b'); webmull('m'); ?>
- array_reverse php
- 'laravel collective"Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
- Y-m-d H:i:s O format
- event angular check it right click
- display errr php
- convert html to pdf php
- create laravel initialize cache
- $user = User::find($request->userid);
- Laravel how to create project
- Malformed UTF-8 characters, possibly incorrectly encoded
- check if key present in array php