note 77516 deleted from language.exceptions by nlopess

From: Date: Sun, 02 Sep 2007 10:20:11 +0000
Subject: note 77516 deleted from language.exceptions by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-130094@lists.php.net to get a copy of this message
Note Submitter: bishop (php at ideacode dot com) ---- Note that throw is a language construct (see http://php.net/manual/en/reserved.php) not a function, which prevents you from using compact expressions such as: <?php function inverse($v) { is_numeric($v) or throw new BadArgumentException(); // ... snip } ?> So, you can emulate it with a little wrapper: <?php function toss($e) { throw $e; } function inverse($v) { is_numeric($v) or toss(new BadArgumentException()); // ... snip } ?> Because the Exception is instantiated in the same place, the stack trace inside the exception is the same. http://bytejar.com/ - Software Lessons Learned the Hard Way

« previous php.notes (#130094) next »