Exception() base doesn't include the method, but the properties ($e->line,
and $e->file I *believe*, check the docs) are protected so you should be
able to implement your own setFile() and setLine() methods from the extended
Zend_Exception.

John

--
John Coggeshall
Team Lead NA Pro. Services
Zend Technologies
 

> -----Original Message-----
> From: Bill Karwin [mailto:[EMAIL PROTECTED] 
> Sent: Monday, December 18, 2006 12:57 PM
> Cc: Aleksey V. Zapparov; Zend Framework General
> Subject: Re: [fw-general] Re: Do we really need Zend::exception()?
> 
> Okay I just tried this:
> 
> <?php
> function testException()
> {
>     require_once 'Zend.php';
>     try {
>         $x = Zend::exception('Zend_Exception', 'boo!');
>         throw $x;
>     } catch (Zend_Exception $e) {
>         echo "{$e->getMessage()}\n";
>         echo "file: {$e->getFile()}\n";
>         echo "line: {$e->getLine()}\n";
>         echo "trace: {$e->getTraceAsString()}\n";
>     }
> }
> 
> testException();
> ?>
> 
> 
> The output is:
> 
> --------
> boo!
> file: C:\zf\library\Zend.php
> line: 229
> trace: #0 C:\zf\library\testex.php(6): 
> Zend::exception('Zend_Exception',
> 'boo!')
> #1 C:\zf\library\testex.php(16): testException()
> #2 {main}
> --------
> 
> You're right, it isn't the line where it's thrown.  It 
> reports the file and line where the exception class is 
> instantiated, inside the
> Zend::exception() function.  But the stack trace shows where the
> Zend::exception() function was called.
> 
> I changed the it to the more traditional:
> 
>         throw new Zend_Exception('boo!');
> 
> And the output changed to this:
> 
> --------
> boo!
> file: C:\zf\library\testex.php
> line: 8
> trace: #0 C:\zf\library\testex.php(15): testException()
> #1 {main}
> --------
> 
> Regarding John's suggestion:  the Exception class has no methods
> setFile() or setLine().
> 
> Regards,
> Bill Karwin
> 
> 
> Darby Felton wrote:
> > Hi all,
> >
> > Zend::exception() only returns an exception; it does not currently 
> > throw an exception, by design, to avoid such obfuscation:
> >
> > throw Zend::exception('SomeException', 'Some Message');
> >
> > Best regards,
> > Darby
> >
> > Bill Karwin wrote:
> >   
> >> Nico Edtinger wrote:
> >>     
> >>> With Zend::exception() we avoid loading all those 
> exception classes 
> >>> that are only needed if an error occurs, which should be 
> an exception.
> >>> So instead of loading these files or at least stat()ing 
> it with an 
> >>> opcode cache we waste some lines in a file that's loaded anyway. 
> >>> That has nothing to do with bugs in any class.
> >>>       
> >> But it's a good point that this method causes stack traces 
> to become 
> >> obfuscated.  It reports the __FILE__ and __LINE__ of the 
> exception as 
> >> occurring in Zend::exception, because that's where the 
> exception is 
> >> actually thrown.
> >>
> >> Regards,
> >> Bill Karwin
> >>
> >>
> >>     
> >
> >
> >   
> 


Reply via email to