Advertisement
mvsp

aula15.php

Jul 22nd, 2021
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. <?php
  2. //Ocorrência anormal que afeta o funcionamento da aplicação
  3. //Exception é a classe base para todas as Exceptions
  4. //message, code, file, line
  5.  
  6. class Newsletter{
  7.     public function cadastrarEmail($email){
  8.         if(!filter_var($email, FILTER_VALIDATE_EMAIL)):
  9.             throw new Exception("Este email é inválido", 1);
  10.         else:
  11.             echo "Email cadastrado com sucesso!";
  12.         endif; 
  13.     }
  14. }
  15.  
  16. $newsletter = new Newsletter;
  17.  
  18. try{
  19. $newsletter->cadastrarEmail("contato@");
  20. } catch(Exception $e) {
  21.     echo "Mensagem: ".$e->getMessage()."<br>";
  22.     echo "Código: ".$e->getCode()."<br>";
  23.     echo "Linha: ".$e->getLine()."<br>";
  24.     echo "Arquivo".$e->getFile()."<br>";
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement