0

Say, for example, I have a MailQueue class with a function queue, which takes a from address, a subject, a body, and an array of recipients. The function validates the given parameters for presence and email address validity, and then attempts to insert the message into the database ready for sending when the queue is next processed. If any of the function parameters fail validation, I throw an exception (say of type InvalidArguementException), and if the database insert fails, I have a custom database exception to throw (say of type DatabaseException).

Do I declare in my PHPDoc comment that I throw both types of exception (multiple @throws lines), or am I going about this the wrong way entirely?

Mike Pearson
  • 79
  • 1
  • 5
  • try looking into [php-Fig](http://www.php-fig.org/) for such answers – Martin Oct 31 '17 at 10:11
  • I think you can do both. but if the validation fails the data should not be inserted and throws an exception first. – Shahroze Nawaz Oct 31 '17 at 10:46
  • @ShahrozeNawaz - that is what I have at the moment, obviously if the validation fails it wouldn't make sense to try and insert. It's not really the order of execution I was questioning, more the way I am throwing multiple types of exceptions in one function. I read something earlier about throwing more than 1 type of exception in any function is bad practice... – Mike Pearson Oct 31 '17 at 10:51

0 Answers0