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

From: Date: Fri, 01 Jul 2005 16:59:51 +0000
Subject: Re: [PEPr] Changes in proposal for File Formats::File_Fortune
References: 1 2 3 4  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-38416@lists.php.net to get a copy of this message
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 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. 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 > 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 { } > 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). > > 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/ > > Thanks! > Cheers, -- Sérgio Carvalho

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