Re: Re: [PEPr] Changes in proposal for File Formats::File_Fortune

From: Date: Sat, 02 Jul 2005 00:22:00 +0000
Subject: Re: Re: [PEPr] Changes in proposal for File Formats::File_Fortune
References: 1 2 3 4 5  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-38417@lists.php.net to get a copy of this message
On 7/1/05, Sergio Carvalho <sergio.carvalho@portugalmail.com> wrote: > Matthew Weier O'Phinney wrote: > > I've read the document, and have some questions on how to proceed. > > > > Should the exception classes utilized by the package be within the same file > > as the class throwing them, or in their own file and/or individual files? > > In their own file. This should be in the document, as it is a slight > violation of CG: Exception classes should be placed in a file called > Exception.php in the topmost directory of your package. In your case: > File/Fortune/Exception.php The RFC should probably be updated to indicate this. But it makes good sense. > This file should contain all exception classes. They are together in one > file because exception classes are typically very small, and serve only > to encode the error class hierarchy. That's what I was thinking; glad to see I'm on the right track, then. > If you feel corageous, the document that served as the basis for the RFC > is more verbose but explains usage a lot better: > > http://wiki.ciaweb.net/yawiki/?area=PEAR_Dev&page=RfcExceptionUse I'm making my way through that now. > > And what is suitable for an exception class definition? For example, would > > the following be enough: > > > > require_once 'PEAR/Exception.php'; > > > > class File_Fortune_Exception extends PEAR_Exception > > { > > } > > For your case, something like: > > class File_Fortune_Exception extends PEAR_Exception > { > } > > class File_Fortune_FileOpenException extends File_Fortune_Exception > { > } > > class File_Fortune_FileLockException extends File_Fortune_Exception > { > } > > class File_Fortune_FilePositionException extends File_Fortune_Exception > { > } Makes sense. > > Or would this be where the error constants should come into play (i.e., to > > map errors to messages)? > > You'll need to use error constants only if you plan to use the same > codebase, or a very similar codebase for PHP4 and PHP5 packages. The > exception class name converys the exact same information as the constant > (i.e. allows users to filter out by error type). Okay. So it looks like a new exception class for each error type. I'd been thinking that a single exception class, and then handling based on the argument passed (error code). But this is probably easier. > > A link to a package that makes good use of PEAR_Exception would help. > > This is still a proposal, but should suffice: > http://pear.sergiocarvalho.com/source/XML_RPC2-0.0.3/XML/RPC2/ Excellent -- that helps tremendously. I'll start incorporating this information, re-write a few tests, and get a new package up. Thanks for your help, Sergio! -- Matthew Weier O'Phinney mweierophinney@gmail.com http://weierophinney.net/matthew/

« previous php.pear.dev (#38417) next »