In PHP, the keyword __________ triggers the exception-handling mechanism.
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:
- adding header function to href php
- check if substring is present php
- error_reporting e_all & e_notice not working
- convert string to uppercase php
- echo err in php
- dompdf/dompdf v1.0.0 requires ext-dom * -> the requested PHP extension dom is missing from your system.
- PHP Fatal error: Uncaught Error: Call to undefined function mcrypt_encrypt()
- check format have image laravel
- array unicode php
- check method in laravel
- date time to timestamp php
- datetime manual date format
- Class 'App\Http\Controllers\Session' not found
- check gettype is string php
- alert js in php
- cakephp find_in_set
- check whether key exists in associative array php
- artisan make auth
- Authorization header (API Key) is missing" }in guzzle
- check if string contains substrin php
- check if array element is set php
- consolelog php response
- check if word include string
- $this