exception get short message 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:
- content for php.ini created manually
- laravel::all()->distinct()->get();
- #1071 - Specified key was too long; max key length is 767 bytes voyger laravel
- date() day php
- current data in php
- error reporting in php
- convert key to value php
- extract data from api callback php
- data php format
- adding spasifc date to date('Y-m-d H:i:s') php
- clear cache laravel command
- Interval Between Different Dates
- fgets function in php
- check if string contains . php
- array duplicating value searching using php
- check key exist in json php
- artisan clear commands
- create random password in php
- count string lengh php
- brew php version
- acf add options page to custom post type
- acf get field
- cache->clear all laravel
- check conatin word php