Re: Exception misinformation
| From: | Hans_L | Date: | Thu, 08 Jul 2004 13:03:36 +0000 |
| Subject: | Re: Exception misinformation | ||
| References: | 1 2 3 4 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-31746@lists.php.net to get a copy of this message | ||
Lukas Smith wrote:
I also think that opening a database connection should throw an exception.I happen to agree that Java is not a perfect rolemodel, but it has nothing to do with strongly typed nature of Java. Indeed, PHP language may make it easier to return mixed types (you could do it in Java too, just a little more work) but that only ends up placing a bigger responsibility on the developer to check values of return types before using them. This is obviously the big downfall of return-code-based error handling: it's more work, as it forces the developer to implement "catch" at every level of the stack regardless of where it actually makes sense (defines a unit, adds meaning, etc.). I think the real reason that Java and C# (and perhaps Python, but I don't know), are not the best role models is that these are completely OO languages. These languages enforce a system that has very controlled (and few) entry points, so ensuring that all exceptions are handled is easier than in PHP. PHP, on the other hand, does provide a set_exception_handler() as a way to provide a convenient top-level try/catch. I think in general PHP OO could learn a lot from these more mature languages; indeed the fact that Exception now is part of PHP is a good example of this learning. HansI'll launch you a challenge. Java is a mature language, that has had exceptions since its inception. Go through the Java standard library: http://java.sun.com/j2se/1.4.2/docs/api/ and find usage of return codes for errors. For reference, the equivalent to DB::connect is here: http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Driver.htmlas Philippe pointed out Java as severe limitations that make it a less than ideal rolemodel for us: namely its a strongly typed language.