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
Is die() dead, and ONLY use exceptions?
Moderator: General Moderators
-
jeff00seattle
- Forum Commoner
- Posts: 66
- Joined: Sat Feb 28, 2009 3:27 pm
Re: Is die() dead, and ONLY use exceptions?
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.
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?
die() and exceptions do different things and are not interchangeable.
-
jeff00seattle
- Forum Commoner
- Posts: 66
- Joined: Sat Feb 28, 2009 3:27 pm
Re: Is die() dead, and ONLY use exceptions?
Since exceptions are available, then when is die() is okay?tasairis wrote:People using frameworks should use exceptions. People not using frameworks should still try to use exceptions, but sometimes a die() is okay.
Thanks for your reply
Re: Is die() dead, and ONLY use exceptions?
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.
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.