catch php exception
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 n in php
- create new project laravel step by step
- find char in string php
- array unique php by value
- exposé tinker laravel
- db seed laravle
- check lenght in php
- echo date php format
- Type error: Argument 1 passed to Illuminate\Database\Grammar::parameterize()
- check if a word contains python
- disable laravel cache
- phptry catch
- add day to time php
- How to display MySQL data dynamically using jQuery and PHP
- In PHP, the keyword __________ triggers the exception-handling mechanism.
- add unique value in array php
- display errr php
- convert image to base64 php
- codeigniter query builder order by
- customizing php time format based on location usa europe
- check if word belongs in string
- date method php
- [ERROR] InvalidArgumentException: Wrong file in C:\xampp\htdocs\magento2.4\lib\internal\Magento\Framework\Image\Adapter\Gd2.php:64 Stack trace
- encontrar un caracter en un strin php