Extending Exception to contain method name

Posted on 16th Feb 2014 by admin

I was wondering, if there's a way to extend Exception in such a way, that it would contain name of a method where it has been thrown.
Right now I have this:


class myException extends Exception {

protected $method;

public function __construct($message, $method, $code = 0, Exception $previous = null) {
$this->method = $method;
parent::__construct($message, $code, $previous);
}

public function getMethod() {
return $this->method;
}
}

but passing __METHOD__ as a parameter whenever exception is thrown doesn't look really good...

[edit]

Oh wait a second... I can get it from trace, can't I?

Other forums