Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.
Moderator: General Moderators
Gambler
Forum Contributor
Posts: 246 Joined: Thu Dec 08, 2005 7:10 pm
Post
by Gambler » Wed Jun 21, 2006 2:20 pm
Do you use inheritance or error codes? Do you create separate file for each exception class?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jun 21, 2006 2:31 pm
inheritance.. yes.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Jun 21, 2006 2:32 pm
Do you create separate file for each exception class?
Typically yes, it keeps things much, much cleaner IMO.
Oren
DevNet Resident
Posts: 1640 Joined: Fri Apr 07, 2006 5:13 am
Location: Israel
Post
by Oren » Wed Jun 21, 2006 3:23 pm
Sounds interesting... What do you mean a class for exceptions?
For me, the word 'exceptions' in PHP means one thing:
Code: Select all
if (some_error_occurs)
{
throw new exception('Error message');
}
Is there more than that?
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Jun 21, 2006 3:29 pm
Code: Select all
require_once 'config/exception.php';
class App_Configuration
{
public function __construct()
{
if ($someCondition)
{
throw new App_Configuration_Exception('Error Message');
}
}
}
Oren
DevNet Resident
Posts: 1640 Joined: Fri Apr 07, 2006 5:13 am
Location: Israel
Post
by Oren » Wed Jun 21, 2006 3:42 pm
Thanks Jcart . Can you show me what's inside exception.php ?
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Jun 21, 2006 4:49 pm
I don't use exception at all
I'm still in PHP4 boat
Oren
DevNet Resident
Posts: 1640 Joined: Fri Apr 07, 2006 5:13 am
Location: Israel
Post
by Oren » Wed Jun 21, 2006 4:52 pm
Then move on
It took me a while too until I made the move, but now I'm happy with it
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Jun 21, 2006 4:56 pm
Unfortunately I have to support huge, slowly dying system written in php4 (register_globals, magic_quotes_gpc, all that crap) =/.
Gambler
Forum Contributor
Posts: 246 Joined: Thu Dec 08, 2005 7:10 pm
Post
by Gambler » Wed Jun 21, 2006 9:25 pm
Code: Select all
<?php class MyException extends Exception{} ?>
Isn't it a bit empty for a separate file?
Oren
DevNet Resident
Posts: 1640 Joined: Fri Apr 07, 2006 5:13 am
Location: Israel
Post
by Oren » Thu Jun 22, 2006 2:21 am
Oh thanks
Gambler . Now I remember I've read about it when I first read about exceptions on the Zend site.
Thanks alot guys
Oren
DevNet Resident
Posts: 1640 Joined: Fri Apr 07, 2006 5:13 am
Location: Israel
Post
by Oren » Thu Jun 22, 2006 3:23 pm
So why this:
Code: Select all
class MyException extends Exception{}
is better than this:
Code: Select all
throw new exception('Error message', 1);
Why not using error codes like in the above example?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jun 22, 2006 3:25 pm
class names are more portable and easier to handle (consistency among other things) .. there's also having localized text be handled by the output based on what the object it gets instead of having to interrogate its innards to figure out what it got, let alone what to do with it.
Oren
DevNet Resident
Posts: 1640 Joined: Fri Apr 07, 2006 5:13 am
Location: Israel
Post
by Oren » Thu Jun 22, 2006 3:27 pm
I see. Thanks a lot
feyd
bg
Forum Contributor
Posts: 157 Joined: Fri Sep 12, 2003 11:01 am
Post
by bg » Thu Jun 22, 2006 6:57 pm
can someone post a practical use of an exception, like a code example? I'm looking at the example given on php's site and its not helping me too much to understand whats going on. Can you throw exceptions without a try block? is it useful, if so, when? I appreciate any help in advance.