Page 1 of 1
Is die() dead, and ONLY use exceptions?
Posted: Tue Mar 02, 2010 5:30 pm
by jeff00seattle
Hi
I have been told that since the advent of exception handling within PHP, that nobody should never ever use die(), trigger_error(), and set_error_handler() any more. Is this a true statement. Is this an expectation within PHP coding standards?
That all error handling should be performed using only exceptions and custom exceptions.
Advise
Thank
Jeff in Seattle
Re: Is die() dead, and ONLY use exceptions?
Posted: Tue Mar 02, 2010 6:37 pm
by requinix
People using frameworks should use exceptions. People not using frameworks should still try to use exceptions, but sometimes a die() is okay.
As for not using trigger_error and set_error_handler, I totally disagree. Sometimes I want to raise an error without raising an exception.
Re: Is die() dead, and ONLY use exceptions?
Posted: Tue Mar 02, 2010 6:40 pm
by Eran
die() and exceptions do different things and are not interchangeable.
Re: Is die() dead, and ONLY use exceptions?
Posted: Tue Mar 02, 2010 7:23 pm
by jeff00seattle
tasairis wrote:People using frameworks should use exceptions. People not using frameworks should still try to use exceptions, but sometimes a die() is okay.
Since exceptions are available, then when is
die() is okay?
Thanks for your reply
Re: Is die() dead, and ONLY use exceptions?
Posted: Tue Mar 02, 2010 8:58 pm
by requinix
Exceptions let you interrupt control flow to respond to an error. Maybe you don't need to.
Maybe you don't need to display a fancy error to the user. Maybe a simple error message will suffice. Maybe all you need is a simple application and a user-friendly response would give no added benefit.