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

Your name:

Reply:


Posted by Marcus Boerger on 10/04/26 11:23

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация