Advertisement
Geicy

Untitled

Jul 30th, 2021
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  1. <?php
  2.  
  3. class Newsletter {
  4.     public function cadastrarEmail($email){
  5.  
  6.         if(!filter_var($email, FILTER_VALIDATE_EMAIL)):
  7.             throw new Exception("Este email é invalido", 1);
  8.         else:
  9.             echo "Email cadastrado com sucesso!";
  10.         endif;
  11.  
  12.     }
  13. }
  14.  
  15. $newsletter = new Newsletter();
  16.  
  17. try{
  18. $newsletter->cadastrarEmail("contato@acom");
  19. } catch(Exception $e){
  20.     echo "Mensagem: ".$e->getMessage()."<br>";
  21.     echo "Código: ".$e->getCode()."<br>";
  22.     echo "Linha: ".$e->getLine()."<br>";
  23.     echo "Arquivos: ".$e->getFile()."<br>";
  24. }
  25.  
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement