Re: [PHP-DEV] Re: [PHP] Exceptions: function x throws Exception

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

 



Hello Jochem,

  lookup the archieves. We have long ago decided agains that.

marcus

Friday, August 5, 2005, 2:26:04 PM, you wrote:

> Dear Internals,

> class FooBar { public function foo() throws Exception {} }
> function fooFoo() throws Exception {}

>         this came up on php-generals and I wondered if anyone had time/cared
> to comment if it (as it does to me) seems like a good idea and/or whether it is
> technically feasable. My thinking was that one could then use the reflection API
> to determine whether functions/methods are capable of throwing exceptions and or
> what kind - might be quite handy when using third party apps/classes
> (PEAR springs to mind.)

> thanks and regards,
> Jochem


> <the rest is blabla aimed at php-generals>

> Torgny Bjers wrote:
>> Norbert Wenzel wrote:
>> 
>>>If there is a class with a function, that might throw exceptions and
>>>does NOT catch them, may I write that like in Java?
>>>
>>>class FooClass {
>>>
>>>    public function foo() throws Exception {

> think about this, especially in terms of the Reflection API, it sounds
> like a really good idea (at least to me)

>>>
>>>    }
>>>
>>>}
>>>
>>>Or is there another possibility to tell a function throws an exception
>>>and to force the caller to handle that exception?
>>>
>>>thanks in advance,
>>>
>>>Norbert
>>>
>> 
>> 
>> Hello Norbert,
>> 
>> The Java way doesn't work here. The best approach would be to simply run
>> a try/catch/finally around the call to your function/method, and inside
>> the function itself you do the following:
>> 
>> if (...) { throw new Exception("My message."); } }
>> 

> indeed - bottom line is you have to know that a function/method/extension may
> throw. mostly you do know because:

> 1. you wrote the code,
> 2. or it's documented in the extension manual pages
> 3. and/ro you hit an unacaught exception whilst developing.

> my approach to cover any oversights is to wrap every thing in a main try/catch block
> just in case - keeping in mind that the idea is that this 'main' catch block is never run
> is al goes well.

>> Regards,
>> Torgny
>> 




Best regards,
 Marcus

-- 
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