php - Would it be an acceptable practice to call methods in Exception constructor? -


i have custom exception class defined this:

class eppexception extends exception {     public function __construct($text, $code, $message = null)      {         epphelper::logerror($text, $code, $this->gettraceasstring, $message);         parent::__construct($text, $code, null);     } } 

and exception thrown

throw new eppexception($text, $code, $message); 

my question - acceptable design point of view use constructor not initialize object carry on additional tasks calling static method in case?

update

another option create static method handles logging , throws exception

class eppexception extends exception {     public function __construct($text, $code, $message = null)      {                parent::__construct($text, $code, null);     } }  public static function raiseexception($text, $code, $message = mull) {     epphelper::logerror($text, $code, $this->gettraceasstring, $message);     throw new eppexception($text, $code, $message); }  epphelper::raiseexeption($text, $code); 

the problem approach mess stack trace

no.

business logic in constructor makes code untestable.

besides which, not job of exception or emitter perform logging, job of exception handler take appropriate action, may including logging error somewhere.


Comments