The Daily WTF
Object-oriented languages often let you implement your own exception classes to hook into their structured exception handling. This is, usually, a good thing: you create your own custom types for your various errors, which makes various exception states more clear. PebkacException is more useful than just Exception, and you can build catch blocks specific to your application/API needs.
But there’s a dark side to this feature. People want to hook functionality into their exception objects. Instead of just using them as a signal to announce a failure state, they slap features into them, like exceptions which automatically self log.
Muriel discovered this PHP SelfLoggingException object when trying to throw an exception caused the application to crash with a stack overflow.
class SelfLoggingException extends Exception { protected $cause = null; public function __construct($message, $cause) { if (!is_null($cause)) { $this->cause = $cause; } parent::__construct($message, 0, null); $logger = LoggerProvider::get(‘exceptoin’); $logger->warn($message); }
To read the full article click on the 'post' link at the top.