|
Posted by Gerard Samuel on 01/17/05 18:43
Jason Barnett wrote:
> 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.
Best explaination yet. This was what I was trying to convey in my previous
reply. With this explaination, it makes total sense, as to what I was
experiencing
with __autoload().
I think we could kill this thread, unless someone wants to bash the theory,
and put us in a tail spin.. :)
Thanks
>
> 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 ;)
>
>
>
[Back to original message]
|