php - Creating new Exception classes, new arguments -
i writing new code in want use self defined exceptions. instance tablecreationfailedexception
. since i'm using php base class deriving exception
class.
in case of particular exception needs hold table not created.
i'm wondering how best have table field in exception set. required argument in constructor seems way go. put new argument @ front of argument list? shall drop message , arguments if not expect them needed? conventions here, if any?
there no hard , fast rules; work fine:
class tablecreationfailedexception extends \exception { public function __construct($table, \exception $previous = null) { parent::__construct("table $table not created", 0, $previous); } }
in case put specialized argument $table
in front of ones parent exception constructor accept.
it's advisable make sure can chain exceptions adding $previous
constructor arguments.
i've left out $code
, hardcoded 0
; add this:
public function __construct($table, $code = 0, \exception $previous = null) { parent::__construct("table $table not created", $code, $previous); }
Comments
Post a Comment