I wish that were the case, but not so much.

We actually did have this functionality, and removed it for various reasons, you can look back at this post:

http://www.nabble.com/Re-3A-Do-we-really-need-Zend-3A-3Aexception-28-29--to7929347s16154.html#a7929347

for conclusions.

As for the code behind stacks, hope this helps:



C:\Documents and Settings\rschindler\My Documents\tests>cat etest.php
<?php

class E_Factory
{
  static public function getException()
  {
    $e = new Exception();
    return $e;
  }
}

class E_Thrower
{
  public function sayEFactory()
  {
    throw E_Factory::getException();
  }
  public function sayE()
  {
    throw new Exception();
  }
}


$c = new E_Thrower();

echo 'From factory - getLine() says: ';

try {
  $c->sayEFactory();
} catch (Exception $e) {
  echo $e->getLine();
}

echo PHP_EOL . 'From direct  getLine() says: ';

try {
  $c->sayE();
} catch (Exception $e) {
  $t = $e->getTrace();
  echo $e->getLine();
}

C:\Documents and Settings\rschindler\My Documents\tests>php etest.php
From factory - getLine() says: 7
From direct  getLine() says: 20


This was also actually implemented at one point, then we took it out for that exact reason.



Jordan Moore wrote:
It's at the throw, not at instantiation.

On Dec 14, 2007 12:14 PM, Ralph Schindler <[EMAIL PROTECTED]> wrote:
I'm just going off memory right now, but I think stack traces for
exception objects are wound up from the point which they are created,
not the point which they are thrown from.  So this would mean that when
you look at the trace from the exception, it originates from the
getException method, rather than the place you are wanting to throw it from.


-ralph


Shekar C Reddy wrote:
I would suggest to incorporate a method that serves as a central
location to instantiate exception objects - a *consistent
*object-instantiation system, if you will. This method could go inside
a class that is always required/loaded so we don't have to include
another file just for this purpose. Zend_Loader, maybe? This approach
allows us to add more processing/error-handling logic to the method in
future that ripples across the framework:

//////////////////////////////////////////////////////////////////////////
static function getException( $class, $message = 'ERROR', $code = 0, ... )
//////////////////////////////////////////////////////////////////////////
{
   self::loadClass( $class );
   //
     // Or straight require_once for performance, but then format the
class-name to instantiate...
// require_once( $class );
   //
   return new $class( $message, $code, ... );


Reply via email to