Quelles sont les exceptions et leurs rôles en PHP ?

Asked  Nov 21, 01:02 pm 39 Views Add Your Answer
Asked  Nov 21, 01:02 pm
Php
0 Dislikes
0 Comments

1 Answers

Added  Nov 23, 12:35 pm

An exception is an object that describes an error or unexpected behaviour of a PHP script. Exceptions are thrown by many PHP functions and classes. User defined functions and classes can also throw exceptions. Exceptions are a good way to stop a function when it comes across data that it cannot use.

Example

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

echo divide(5, 0);
?>

More w3schools

1 Likes 0 Dislikes
0 Comments
×
Google login
SignUp with Email
X