exception handling 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:
- check if key present in array php
- find length of string in php
- base encode64 php
- convert small to capital in php
- 8 digit random number generator in php
- $age = 20; print ($age >= 18) ? "Adult" : "Not Adult";
- adding days to a date in php
- Laravel Validation check array size min and max
- current month date wise how to print in php
- array check duplicates php
- date increase 1 day
- Get the number of days between two dates in PHP
- Difference in days of two dates in php
- decode base64 with key php
- Best Performance monitoring tools for php
- eloquent pluck multiple columns
- check if key exists array
- $conn = new PDO(
- check if variable is set and not empty laravel
- catch exception in php
- Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
- check if next key is array or object in php
- codeigniter db insert return id
- codeigniter load form_validation