Search
 
SCRIPT & CODE EXAMPLE
 

PHP

why do we use php exceptions

<?php
  
  #We use exceptions to handle errors in PHP
  
  function divide($dividend, $divisor) {
  	if($divisor == 0) {
    	throw new Exception("Division by zero");
  	}
  return $dividend / $divisor;
}

echo divide(5, 0);
  
?>
Comment

php catch exception


<?php
function inverse($x) {
    if (!$x) {
       throw new Exception('Division durch Null.');
    }
    return 1/$x;
}

try {
    echo inverse(5) . "
";
    echo inverse(0) . "
";
} catch (Exception $e) {
    echo 'Exception abgefangen: ',  $e->getMessage(), "
";
}

// Ausführung fortsetzen
echo "Hallo Welt
";
?>

Comment

PHP Exceptions

<?php
function divide($dividend, $divisor) {
  if($divisor == 0) {
    throw new Exception("Division by zero");
  }
  return $dividend / $divisor;
}

echo divide(5, 0);
?>
Comment

PREVIOUS NEXT
Code Example
Php :: laravel skip a loop if error 
Php :: get the value without setter method laravel 
Php :: what is php 
Php :: trim php 
Php :: if else in one line php 
Php :: send gmail 
Php :: how to add an array into an associative array in php 
Php :: spatie/laravel-activitylog display only changed data 
Php :: how to split sting in php 
Php :: str_contains — Determine if a string contains a given substring 
Php :: php versions and features 
Php :: laravel showing index of problem 
Php :: relationship in laravel 
Php :: laravel.com relationship 
Php :: if php 
Php :: how to update dropdown value in laravel 
Php :: php implode in html tags 
Php :: laravel.log" could not be opened in append mode 
Php :: Array (key and value) 
Php :: laravel lumen 
Php :: laravel admin disable batch selection 
Php :: Eloquent orWhere clousure 
Php :: converting php to codeigniter 
Php :: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in C:xampphtdocsJob Verificationlogin esult.php on line 38 
Php :: php datenbank beschreiben 
Php :: Laravel: Foreign id does not have default value 
Php :: Initialisez un tableau de 4 cases (contenant des nombres) et en faire la somme en créant une fonction somme php 
Php :: php generator for mysql 
Php :: No match for argument: phpmyadmin yum 
Php :: razorpay refund laravel 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =