exception php
function inverse($x) {
if (!$x) {
throw new Exception('Division by zero.');
}
return 1/$x;
}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. try
{
// Some code...
}
catch(AError | BError $e)
{
// Handle exceptions
}
catch(Exception $e)
{
// Handle the general case
}<?php
function inverse($x) {
if (!$x) {
throw new Exception('Division durch Null.');
}
return 1/$x;
}
try {
echo inverse(5) . "\n";
echo inverse(0) . "\n";
} catch (Exception $e) {
echo 'Exception abgefangen: ', $e->getMessage(), "\n";
}
// Ausführung fortsetzen
echo "Hallo Welt\n";
?>
Also in PHP:
- ->with('success'
- clear laravel.log
- array key is true
- create new laravel project 8
- date time stamp php
- basd64 decrtpy php
- date php :w3schools.com
- change native password in phpmyadmin
- command to install php5.4 in ubuntu 18.04
- current date into time
- count length of string pphp
- asia time zone in php
- SET CURRENT DATE TIME IN PHP'
- $get url php
- check chartercount in php
- convert dd/mm/yyyy to yyyy-mm-dd in mysql php
- PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Sp ecified key was too long; max key length is 1000 bytes")
- Allowed memory size of 33554432 bytes exhausted (tried to allocate 5287496 bytes) on laravel
- array should not be empty php
- ERROR: Module mpm_event is enabled - cannot proceed due to conflicts. It needs to be disabled first! Considering conflict mpm_worker for mpm_prefork: ERROR: Could not enable dependency mpm_prefork for php7.2, aborting
- base64 to string pp
- convert caps to sentese case php
- adding spasifc date to date('Y-m-d H:i:s') php
- cache and compile file clear laravel