can you use just 1 try catch in a php function
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:
- add 1 day to date using php
- displaying errors in laravel
- PHP make an image from a random alphanumerric string
- date() php -1heure?
- catch multiple exceptions php
- array size php
- config cache clear in laravel
- date u 1 day php
- can you use just 1 try catch in a php function
- check character present in sentence in phph
- count charctor in php
- create path php
- check if substring in php
- DATABASE CONNEC
- display php error
- check if string has character php
- disable login and register in laravel
- $_Server php find
- array key exists php
- base64_decode image string php
- char position in string php
- create random password php
- add days to date php
- error reporting off