Re: Re: PHP5 silently throwing exceptions???

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Gerard Samuel wrote:
Jason Barnett wrote:

Gerard Samuel wrote:

I've debugged it down to this ->
//try
//{
   $db->connect();
//}
//catch(databaseException $e)
//{
//    throw $e;
//}

The ::connect() method is supposed to throw a databaseException if a connection cannot be made.
In my tests, connections are made, and the exception is not thrown.
But the try/catch block above, for some reason, tries to throw
the databaseException (according to __autoload()).
If I comment it out the try/catch block, __autoload()
doesn't try to load the databaseException object.



Um, perhaps you have things a little mixed up? __autoload is only used to get a definition for an unknown class; it doesn't actually do any object instantiation. It's used for "just in time" loading of a class definition if and only if the class / file hasn't already been included.



While I understand what you mean, what my chain of thought was at the time, is why was an exception being loaded "just in time", and not being thrown. And I think I know why it was doing what it was doing in my case. I may be wrong here, but the line -> catch(databaseException $e) is what is *initiating* an exception object if it doesn't exist.

Ah, I get what you are saying now. I think you're closer with this guess, but I believe the actual code execution is something along the lines of:


0. Begin try { } block
1. Enter ::connect()
2. ::connect() fails and you throw the exception (exception would be instantiated here, __autoload is used etc.)


OR

2a. ::connect() succeeds and normal code flow resumes
3. The catch() needs to see if there is an exception of type databaseException being passed to it. But in order to perform this check PHP needs the class definition. Hence __autoload for the exception class could also be performed here.


What's the point of the difference between what you stated and what I stated? The catch { } block will only be executed if it is given an exception of type (insert type here). So it needs to check what type of exception PHP might have passed to it, but the code in the catch { } block *doesn't* get executed unless the exception is passed.

My understanding at the time, of try/catch blocks was that it only enters the *catch*
stage, if an exception was thrown.
But it seems in reality, the *catch* stage is actually part of normal code execution path.
This seems to make sense. If true, it would clarify my understanding of the
try/catch block, and why __autoload() is being called on.



I haven't checked the source on this one so I can't guarantee that what I've said above is true, but I believe it to be true. Someone correct me if I'm wrong (wouldn't be the first time ;)




--
Teach a person to fish...

Ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html
PHP Manual: http://www.php.net/manual/en/index.php
php-general archives: http://marc.theaimsgroup.com/?l=php-general&w=2

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux