Which of the following method of Exception class returns the code of exception when error occured?
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:
- check if home page wordpress
- check if id is in key array php
- event rightclick mouse
- check datatype in php
- exception php
- To print current time which function will use in pphp
- does array have key php
- convert date and time to time stamp phph
- Illuminate\Contracts\Container\BindingResolutionException Target class [SlugController] does not exist.
- console.log equivalent in php
- convert unix timestamp to timestamp php
- database seeder
- codeigniter get insert iditer print last query
- add 1 day to date php
- PHP File Open/Read/Close
- current uri php[
- check if number is multiple of 3 in php
- date("Y-m-d",
- custom post type with taxonomy
- Fixes duplicate arrays to show a single character. php
- explode php
- date format for month name php
- easiest way to setup a new laravel project
- composer artisan