Advertisement
Guest User

throw exception VS return false

a guest
Feb 16th, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. //moznost #1
  2. public function send()
  3. {
  4.     if (!mail($this->to, $this->subject, $this->message, $headers)) {
  5.         throw new Exception('Send e-mail failed');
  6.     }
  7. }
  8.  
  9. try {
  10.     $mail->send();
  11.  
  12.     $this->setFlashMessage('success', 'E-mail pre obnovenie hesla bol odoslaný na vašu adresu.');
  13.  
  14. } catch (Exception $e) {
  15.  
  16.     $this->setFlashMessage('danger', 'Pokus o obnovenie hesla bol neúspešný.');
  17. }
  18.  
  19.  
  20. //moznost #2
  21. public function send()
  22. {
  23.     if (!mail($this->to, $this->subject, $this->message, $headers)) {
  24.         return false;
  25.     }
  26.  
  27.     return true;
  28. }
  29.  
  30. try {
  31.     if (!$mail->send()) {
  32.         throw new Exception('Send e-mail failed');
  33.     }
  34.  
  35.     $this->setFlashMessage('success', 'E-mail pre obnovenie hesla bol odoslaný na vašu adresu.');
  36.  
  37. } catch (Exception $e) {
  38.  
  39.     $this->setFlashMessage('danger', 'Pokus o obnovenie hesla bol neúspešný.');
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement