catch error in except in 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:
- error message in php
- factoring and seeding in laravel
- 500 server error laravel 7
- $result->result()
- 500 Server Error on laravel
- How do you clear cache in Laravel?
- add checkbox in server side datatable laravel
- bootstrap carousel foreach loop not working wordpressp php wp
- App\Http\Controllers\Validator not found
- PS C:\xampp\htdocs\recruit2> php artisan make:seeder Interviews Seeder Seeder already exists!
- In Connection.php line 1262: Class 'PDO' not found
- easy admin bunfle symfony modify login page
- convert all to uppercase php
- core php redirect to page
- datetime form of date in php
- does array have key php
- php auto refresh page
- check if astring is apart of another string in php
- Jul 29th, 2020 php format
- composer set php version
- check if substring in php
- delete duplicates array php
- codeigniter db last insert id
- create a directory in php if not exists