$this in catch block 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. function inverso($x) {
if (!$x) {
throw new Exception('Zero division.');
}
return 1/$x;
}
try {
echo inverso(5) . "\n";
echo inverso(0) . "\n";
} catch (Exception $e) {
echo 'and the error is: ', $e->getMessage(), "\n";
}
Also in PHP:
- check type of in php
- Undefined index: $fileName = basename($_FILES["file"]["name"]);file in D:\xampp\htdocs\upload.php on line 12
- Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 9263312 bytes) in /home/arsalan farooq/local security.uk/wp-includes/wp-db.php
- date('hms'
- blade if
- Connecting that to Database using PHP.
- base64 encode image php
- $var = '<script> php
- change location php
- disab;e error reporting php
- How do I convert timestamp to epoch time in php
- DESC laravel
- errors php
- create model, controller and migration in single command laravel
- filteredduplicata php
- echo now phpmp
- download laravel project
- @for loop php
- date format method in php
- check if $this-> key exist php
- check if key exists in associative array php
- check if row of array exists php
- 12 hr time format in php
- JavaScript sense right click